怎样实现C语言 连续输入的几个数(同一数组)相加啊?

2025-06-22 15:22:14
推荐回答(5个)
回答1:

#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;

}

回答2:

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];就好了

回答3:

这是一个很简单的问题.但给你弄错了.主要是你的循环嵌套是错误的.你那个外循环每取一个值,就要输入100个分数的.其次,求平均分先要有总分.这就需要累加的.你没有.好好看看一楼的程序.认真理解清楚.朋友.

回答4:

#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();
}

回答5:

下边的回答比较完美,就是对原程序思想修改了,注意在程序变量的定义时要初始化,