|
查看: 989|回复: 12
|
C Language: 算分数
[复制链接]
|
|
|
- /*
- User will be prompt for number of quiz that has been taken.
- User has to input their marks for each quiz.
- Your program will calculate the average of the marks.
- Find the lowest mark of those quizzes.
- Find the 3 highest mark of those quizzes.
- Those highest marks must be in order (from highest to lowest).
- eg:
- Number of quiz taken : 5
- Please input mark for quiz 1: 10
- Please input mark for quiz 2: 30
- Please input mark for quiz 3: 20
- Please input mark for quiz 4: 40
- Please input mark for quiz 5: 60
- Your average mark is 32.
- Your lowest mark is 10.
- The three highest marks for your quizzes are 60, 40, 30.
- */
- #include<stdio.h>
- void main()
- {
- int i,num;
- float mark[10];
- float total,avg;
- float lowest;
- printf("Number of quiz taken : ";
- scanf("%d",&num);
- for(i=0;i<num;i++)
- {
- printf("lease input mark for quiz %d: ",i+1);
- scanf("%d",&mark);
- total=total+mark;
- }
- avg=total/num;
- printf("Your average mark is %.2f.\n",avg);
- lowest=mark[0];
- for(i=0;i<5;i++)
- {
- if(mark<lowest)
- lowest=mark;
- }
- printf("Your lowest mark is %f.\n",lowest);
- }
复制代码 出了什么问题?
请大家指点迷津。。。
谢谢!~
[ 本帖最后由 蜡笔小烦 于 14-10-2008 06:52 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 08:29 AM
|
显示全部楼层
#include
int main()
{
int count,num;
float mark[10];
float total,avg;
float lowest;
printf("Number of quiz taken : " );
scanf("%d",&num);
for(count=0;count < num; count++)
{
printf(" Please input mark for quiz %d: ",count+1);
scanf("%f",&mark[count]);
total=total+mark[count];
}
avg=total/num;
printf("Your average mark is %.2f.\n",avg);
lowest=mark[0];
for(count=0;count<5;count++)
{
if(mark[count] < lowest){
lowest=mark[count];
}
printf("Your lowest mark is %f.\n",lowest);
}
[ 本帖最后由 bomber27 于 15-10-2008 08:35 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-10-2008 10:53 AM
|
显示全部楼层
原帖由 bomber27 于 15-10-2008 08:29 AM 发表 
#include
int main()
{
int count,num;
float mark[10];
float total,avg;
float lowest;
printf("Number of quiz taken : " );
scanf("%d",&num);
for(count=0;count < num; count++)
{
prin ...
-
- #include<stdio.h>
- int main()
- {
- int count,num;
- float mark[10];
- float total,avg;
- float lowest;
- printf("Number of quiz taken : " );
- scanf("%d",&num);
- for(count=0;count < num; count++)
- {
- printf(" Please input mark for quiz %d: ",count+1);
- scanf("%f",&mark[count]);
- total=total+mark[count];
- }
- avg=total/num;
- printf("Your average mark is %.2f.\n",avg);
- lowest=mark[0];
- for(count=0;count<5;count++)
- {
- if(mark[count] < lowest)
- {
- lowest=mark[count];
- }
- printf("Your lowest mark is %f.\n",lowest);
- }
- }
复制代码
debug 了你这个code后
output 不对哦~
不知道哪里出问题了
看不出来。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 11:32 AM
|
显示全部楼层
output 是什么?
我要看到output后才知道什么问题 |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 12:22 PM
|
显示全部楼层
回复 3# 蜡笔小烦 的帖子
不好意思,刚才因为cari把 [ i] 当成 italic,所以弄到很乱
#include<stdio.h>
int main(){
int count,num;
float mark[10];
float total,avg;
float lowest;
printf("Number of quiz taken : " );
scanf("%d",&num);
for(count=0;count < num; count++){
printf(" Please input mark for quiz %d: ",count+1);
scanf("%f",&mark[count]);
total=total+mark[count];
}
avg=total/num;
printf("Your average mark is %.2f.\n",avg);
lowest=mark[0];
for(count=0;count<num;count++){
if(mark[count] < lowest){
lowest=mark[count];
}
}
printf("Your lowest mark is %f.\n",lowest);
}
这个才是对的 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-10-2008 03:34 PM
|
显示全部楼层
原帖由 bomber27 于 15-10-2008 12:22 PM 发表 
不好意思,刚才因为cari把 [ i] 当成 italic,所以弄到很乱
#include
int main(){
int count,num;
float mark[10];
float total,avg;
float lowest;
printf("Number of quiz taken ...
average mark 还是不对哦~ |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 04:40 PM
|
显示全部楼层
回复 6# 蜡笔小烦 的帖子
不对吗?
我试过了,没有问题啊。。
你用什么compiler? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-10-2008 05:08 PM
|
显示全部楼层
原帖由 bomber27 于 15-10-2008 04:40 PM 发表 
不对吗?
我试过了,没有问题啊。。
你用什么compiler?
Visual C++啊 |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 05:30 PM
|
显示全部楼层
回复 8# 蜡笔小烦 的帖子
没用过
我是用Dev-C++ |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-10-2008 05:46 PM
|
显示全部楼层
原帖由 bomber27 于 15-10-2008 05:30 PM 发表 
没用过
我是用Dev-C++
啊???
-
- /*
- User will be prompt for number of quiz that has been taken.
- User has to input their marks for each quiz.
- Your program will calculate the average of the marks.
- Find the lowest mark of those quizzes.
- Find the 3 highest mark of those quizzes.
- Those highest marks must be in order (from highest to lowest).
- eg:
- Number of quiz taken : 5
- Please input mark for quiz 1: 10
- Please input mark for quiz 2: 30
- Please input mark for quiz 3: 20
- Please input mark for quiz 4: 40
- Please input mark for quiz 5: 60
- Your average mark is 32.
- Your lowest mark is 10.
- The three highest marks for your quizzes are 60, 40, 30.
- */
- #include<stdio.h>
- int main()
- {
- int count,num;
- float mark[10];
- float total,avg;
- float lowest,highest;
- printf("Number of quiz taken : " );
- scanf("%d",&num);
- for(count=0;count<num; count++)
- {
- printf(" Please input mark for quiz %d: ",count+1);
- scanf("%f",&mark[count]);
-
- total=total+mark[count];
- }
- avg=total/num;
- printf("Your average mark is %.2f.\n",avg);
- lowest=mark[0];
- for(count=0;count<num;count++)
- {
- if(mark[count] < lowest)
- {
- lowest=mark[count];
- }
- }
- printf("Your lowest mark is %.2f.\n",lowest);
- highest=mark[0];
- for(count=0;count<num;count++)
- {
- if(mark[count] > highest)
- {
- highest=mark[count];
- }
- }
- printf("Your highest mark is %.2f.\n",highest);
- }
复制代码
以上的我做好了lowest和highest.
average卡住了。
然后不知道第二和第三高分要怎么loop。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 08:53 PM
|
显示全部楼层
|
在你还没有跑for loop之前, 试试放 total=0; |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 15-10-2008 09:11 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 15-10-2008 09:38 PM
|
显示全部楼层
|
先从五个里面找出最高的, 然后踢掉它, 剩四个,再从四个找出最高的, 然后踢掉它,剩三个。。。。一直这样下去。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|