一维数组编译
Ⅰ c语言一维数组
#include "stdio.h"
#define N 30
void main()
{
int grades[N]; //所有人的分数
int upAverage[N]; //超过平均分的学生序号
int unPass[N]; //不及格的学生序号
int nNum = 0; //学生总人数
int nUpAve = 0; //超过平均分的人数
int totGrade = 0; //总分
int n50,n60,n70,n80,n90; //各个分数段人数
double average; //平均分
int i;
//读入成绩
while (1){
scanf("%d",&grades[nNum]);
if (grades[nNum]<0) break;
totGrade += grades[nNum];
nNum++;
}
average = totGrade*1.0/nNum;
//统计各个分数段人数
n50 = n60 = n70 = n80 = n90 = 0;
for (i=0; i if (grades[i] >= average) upAverage[nUpAve++] = i;
if (grades[i] < 60) unPass[n50++] = i;
else if (grades[i] < 70) n60++;
else if (grades[i] < 80) n70++;
else if (grades[i] < 90) n80++;
else n90++;
}
//结果输出
printf("不及格人数: %d\n",n50);
printf("不及格学生序号:");
for (i=0; i printf("\n成绩在全班平均分及平均分之上的学生人数: %d\n",nUpAve);
printf("这些学生序号:");
for (i=0; i printf("\n以直方图方式统计各分数段的学生人数及所占的百分比\n");
printf("\n分数段 \t 学生人数\t图形");
printf("\n <60 \t %2d(%.0lf%%) \t", n50, n50*100.0/nNum); for (i=0; i printf("\n 60-69 \t %2d(%.0lf%%) \t", n60, n60*100.0/nNum); for (i=0; i printf("\n 70-79 \t %2d(%.0lf%%) \t", n70, n70*100.0/nNum); for (i=0; i printf("\n 80-89 \t %2d(%.0lf%%) \t", n80, n80*100.0/nNum); for (i=0; i printf("\n >=90 \t %2d(%.0lf%%) \t", n90, n90*100.0/nNum); for (i=0; i printf("\n");
}