急求,一道c语言编程题, 10
输入10个学生的四门课程成绩(如高等数学、线性代数、大学物理、C语言程序设计),1、统计每名学生的平均分;2、统计平均分在0-60,60-70,70-80,80-90,9...
输入10个学生的四门课程成绩(如高等数学、线性代数、大学物理、C语言程序设计),1、统计每名学生的平均分;2、统计平均分在0-60,60-70,70-80,80-90,90-100的人数(函数实现) 对了就给分,谢谢
展开
2个回答
2014-04-28
展开全部
#include<stdio.h>
#include<windows.h>
int num(float *avg, int n, float from, float to){
int i;
int num = 0;
for(i=0;i<n;i++){
if(to==100)
if(avg[i]>=from&&avg[i]<=to)
num++;
else
if(avg[i]>=from&&avg[i]<to)
num++;
}
return num;
}
int main(){
const int N = 10;
int i;
float avg[N];
float maths,linal,pys,cpg;
printf("Input %d student's score(four classes):\n",N);
for(i=0;i<N;i++){
scanf("%f%f%f%f",&maths,&linal,&pys,&cpg);
avg[i] = (maths+linal+pys+cpg)/4.0;
}
printf("\nAverage score: ");
for(i=0;i<N;i++)
printf("%0.2f ",avg[i]);
printf("\n");
printf("Number of peopeo with average score between 0 and 60: %d\n",num(avg,N,0,60));
printf("Number of peopeo with average score between 60 and 70: %d\n",num(avg,N,60,70));
printf("Number of peopeo with average score between 70 and 80: %d\n",num(avg,N,70,80));
printf("Number of peopeo with average score between 80 and 90: %d\n",num(avg,N,80,90));
printf("Number of peopeo with average score between 90 and 100: %d\n",num(avg,N,90,100));
system("pause");
return 1;
}
更多追问追答
追问
我运行显示一个错误呀哥们,你能帮我再看看吧
追答
我电脑是正常运行的? 你什么错误?
编程环境是VC吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你先测试一下,不行我再修改。。我这边测试没有问题。
#include<stdio.h>
int main(){
float a,b,c,d;
int n=10;
int a1=0,a2=0,a3=0,a4=0,a5=0;
while(n--)
{
scanf("%f %f %f %f",&a,&b,&c,&d);
float s=a+b+c+d/4;
printf("第%d人的平均成绩为%.2f\n",10-n,s);
if(s<60.0)
a1++;
else if(s<70)
a2++;
else if(s<80)
a3++;
else if(s<90)
a4++;
else
a5++;
}
printf("0-60:%d ,60-70:%d,70-80:%d,80-90:%d,90-100:%d",a1,a2,a3,a4,a5);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询