读书人

新手请大家看下比较急多谢了大哥们

发布时间: 2012-03-06 20:47:55 作者: rapoo

新手,请大家看下,比较急,谢谢了大哥们,。。。
下面这个C程序就是分别输入math,english的成绩,开始提示输入学号,然后输入这两门的成绩,输入完后显示这个学生的平均成绩,同时提示是否要在输入一组成绩,按0继续输入一组,按1则退出这一组的输入然后出现所输入的组数,并且计算出aver_math,aver_english所有输入中每一门的平均成绩,为什么结果中每一门的平均成绩总是不和要求呢?数都是很大的,请指点下

#include "stdio.h "
#include "conio.h "

main()
{
int num[100],math[100],english[100],averres[100],i,j;
int a,b;
int logo;
int aver_math,aver_english;
for(i=0,j=0;i <100;i++)
{
printf( "\n please input the study_num:\n ");
scanf( "%d ",&num[i]);
printf( "please input the math:\n ");
scanf( "%d ",&math[i]);
printf( "please input the english:\n ");
scanf( "%d ",&english[i]);
a=math[i];
b=english[i];
averres[i]=aver(a,b);
printf( "average result:\n ");
printf( "%d ",averres[i]);
++j;
printf( "\n now you have completed one student-inputing do you want to exit input?1/0:\n ");
scanf( "%d ",&logo);
if(logo)
{
break;
}
else
continue;
}
printf( "\n total studens ' number:\n ");
printf( "%d ",j);
printf( "\n average_result of each class as the follows :\n ");
printf( "aver_math aver_english\n ");
aver_math=aver_each_math(math[100],j);
aver_english=aver_each_english(english[100],j);
printf( " %d ",aver_math);
printf( " %d ",aver_english);
getch();
}
int aver(int a,int b)
{
int result;
result=(a+b)/2;
return(result);
}
int aver_each_math(int a[100],int num)
{
int total=0,i,result;
for(i=0;i <num;i++)
{total=total+a[i];}
result=total/num;
return(result);
}
int aver_each_english(int a[100],int num)
{
int total=0,i,result;
for(i=0;i <num;i++)
{total=total+a[i];}
result=total/num;
return(result);
}




------解决方案--------------------


aver_math=aver_each_math(math[100],j);
aver_english=aver_each_english(english[100],j);

改成aver_math=aver_each_math(math,j);
aver_english=aver_each_english(english,j);

读书人网 >C语言

热点推荐