#include
int main()
{
int a[100],n,i,s=0;
printf("全班人数:");
scanf("%d",&n);
printf("每人成绩:");
for(i=0;i { scanf("%d",&a[i]); s+=a[i]; } printf("全班总分:%d\n",s); system("pause"); return 0; }
void main()
{
int i,student[100],score[100];
float pingjun=0.0f;
for(i=0;i<100;i++)
{
printf("\nNO.%d student:",i);
scanf("%d",&score[i]);
pingjun+=(float)score[i];
}
pingjun/=100.0f;
printf("pingjun : %d \n",pingjun);
getchar();
}
那你看看这样呢?顺便说一下啊。。。你定义的studen[]数组根本就没有用啊。。建议你如果真的需要使用的话,把它们写在一个结构体里。这样比较简洁。例如
typedef Stu{
char name[20];
double score;
}Student;
然后在程序里。直接Student stu[100];就好了
这是一个很简单的问题.但给你弄错了.主要是你的循环嵌套是错误的.你那个外循环每取一个值,就要输入100个分数的.其次,求平均分先要有总分.这就需要累加的.你没有.好好看看一楼的程序.认真理解清楚.朋友.
#include"stdio.h"
#include"stdlib.h"
void main()
{
int i,student[100],score[100];
float pingjun=0.0f;
for(i=0;i<100;i++)
{
printf("\nNO.%d student:",i);
scanf("%d",&score[i]);
pingjun+=(float)score[i];
}
pingjun/=100.0f;
printf("pingjun : %d \n",pingjun);
gatchar();
}
下边的回答比较完美,就是对原程序思想修改了,注意在程序变量的定义时要初始化,