佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 989|回复: 12

C Language: 算分数

[复制链接]
发表于 14-10-2008 06:24 PM | 显示全部楼层 |阅读模式
  1. /*
  2. User will be prompt for number of quiz that has been taken.
  3. User has to input their marks for each quiz.
  4. Your program will calculate the average of the marks.
  5. Find the lowest mark of those quizzes.
  6. Find the 3 highest mark of those quizzes.
  7. Those highest marks must be in order (from highest to lowest).
  8. eg:
  9. Number of quiz taken : 5
  10. Please input mark for quiz 1: 10
  11. Please input mark for quiz 2: 30
  12. Please input mark for quiz 3: 20
  13. Please input mark for quiz 4: 40
  14. Please input mark for quiz 5: 60
  15. Your average mark is 32.
  16. Your lowest mark is 10.
  17. The three highest marks for your quizzes are 60, 40, 30.
  18. */
  19. #include<stdio.h>
  20. void main()
  21. {
  22. int i,num;
  23. float mark[10];
  24. float total,avg;
  25. float lowest;
  26. printf("Number of quiz taken : ";
  27. scanf("%d",&num);
  28. for(i=0;i<num;i++)
  29. {
  30.   printf("lease input mark for quiz %d: ",i+1);
  31.   scanf("%d",&mark);
  32.   total=total+mark;
  33. }
  34. avg=total/num;
  35. printf("Your average mark is %.2f.\n",avg);
  36. lowest=mark[0];
  37. for(i=0;i<5;i++)
  38. {
  39.   if(mark<lowest)
  40.    lowest=mark;
  41. }
  42. printf("Your lowest mark is %f.\n",lowest);
  43. }
复制代码
出了什么问题?
请大家指点迷津。。。
谢谢!~


[ 本帖最后由 蜡笔小烦 于 14-10-2008 06:52 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 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 ...



  1. #include<stdio.h>

  2. int main()
  3. {
  4. int count,num;
  5. float mark[10];
  6. float total,avg;
  7. float lowest;

  8. printf("Number of quiz taken : " );
  9. scanf("%d",&num);
  10. for(count=0;count < num; count++)
  11. {
  12. printf(" Please input mark for quiz %d: ",count+1);
  13. scanf("%f",&mark[count]);
  14. total=total+mark[count];
  15. }
  16. avg=total/num;
  17. printf("Your average mark is %.2f.\n",avg);
  18. lowest=mark[0];
  19. for(count=0;count<5;count++)
  20. {
  21. if(mark[count] < lowest)
  22. {
  23. lowest=mark[count];
  24. }
  25. printf("Your lowest mark is %f.\n",lowest);
  26. }
  27. }
复制代码


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 还是不对哦~
回复

使用道具 举报

Follow Us
发表于 15-10-2008 04:40 PM | 显示全部楼层

回复 6# 蜡笔小烦 的帖子

不对吗?
我试过了,没有问题啊。。
你用什么compiler?
回复

使用道具 举报

 楼主| 发表于 15-10-2008 05:08 PM | 显示全部楼层
原帖由 bomber27 于 15-10-2008 04:40 PM 发表
不对吗?
我试过了,没有问题啊。。
你用什么compiler?


Visual C++啊
回复

使用道具 举报


ADVERTISEMENT

发表于 15-10-2008 05:30 PM | 显示全部楼层

回复 8# 蜡笔小烦 的帖子

没用过
我是用Dev-C++
回复

使用道具 举报

 楼主| 发表于 15-10-2008 05:46 PM | 显示全部楼层
原帖由 bomber27 于 15-10-2008 05:30 PM 发表
没用过
我是用Dev-C++


啊???


  1. /*
  2. User will be prompt for number of quiz that has been taken.
  3. User has to input their marks for each quiz.
  4. Your program will calculate the average of the marks.
  5. Find the lowest mark of those quizzes.
  6. Find the 3 highest mark of those quizzes.
  7. Those highest marks must be in order (from highest to lowest).
  8. eg:
  9. Number of quiz taken : 5
  10. Please input mark for quiz 1: 10
  11. Please input mark for quiz 2: 30
  12. Please input mark for quiz 3: 20
  13. Please input mark for quiz 4: 40
  14. Please input mark for quiz 5: 60
  15. Your average mark is 32.
  16. Your lowest mark is 10.
  17. The three highest marks for your quizzes are 60, 40, 30.
  18. */
  19. #include<stdio.h>
  20. int main()
  21. {
  22.     int count,num;
  23.     float mark[10];
  24.     float total,avg;
  25.     float lowest,highest;
  26.     printf("Number of quiz taken : " );
  27.     scanf("%d",&num);
  28.     for(count=0;count<num; count++)
  29. {
  30.   printf(" Please input mark for quiz %d: ",count+1);
  31.         scanf("%f",&mark[count]);
  32.         
  33.   total=total+mark[count];
  34.     }
  35.     avg=total/num;
  36.     printf("Your average mark is %.2f.\n",avg);
  37.     lowest=mark[0];
  38.     for(count=0;count<num;count++)
  39. {
  40.   if(mark[count] < lowest)
  41.   {
  42.    lowest=mark[count];
  43.   }
  44.     }
  45.     printf("Your lowest mark is %.2f.\n",lowest);
  46. highest=mark[0];
  47. for(count=0;count<num;count++)
  48. {
  49.   if(mark[count] > highest)
  50.   {
  51.    highest=mark[count];
  52.   }
  53.     }
  54. printf("Your highest mark is %.2f.\n",highest);
  55. }
复制代码

以上的我做好了lowest和highest.
average卡住了。
然后不知道第二和第三高分要怎么loop。。。
回复

使用道具 举报

发表于 15-10-2008 08:53 PM | 显示全部楼层
在你还没有跑for loop之前, 试试放 total=0;
回复

使用道具 举报

 楼主| 发表于 15-10-2008 09:11 PM | 显示全部楼层
原帖由 糯米鸡 于 15-10-2008 08:53 PM 发表
在你还没有跑for loop之前, 试试放 total=0;


可以了
就是漏了这一个。
谢谢!~

我现在在想着要怎么拿到第二高和第三高的分数
回复

使用道具 举报

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

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 03:27 AM , Processed in 0.133829 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表