请编写关于数组的C语言程序

问题描述:

请编写关于数组的C语言程序
任意输入10个学生的成绩存放在数组中,
然后输出最高分、最低分,以及不及格的人数,以其在成绩中人数的比例.
1个回答 分类:综合 2014-11-21

问题解答:

我来补答
#include
#include
#define STU 10 //宏定义学生人数,改起来方便
#define SCORE 60 //学生及格分数线
int main()
{
int score[STU];
int i;
int j;
int t;
int num = 0;
printf("please input ten number:");
for(i = 0; i < STU; i++)
{
scanf("%d",&score[i]);
}
for(i = 0; i < STU; i++)
{
for(j = 0; j < STU-1; j++)
{
if(score[j]>score[j+1])
{
t = score[j];
score[j] =score[j+1];
score[j+1] = t;
}
}
}
printf("The high score is :%d\n",score[STU-1]);
printf("The low score is :%d\n",score[0]);
for(i = 0; i < STU; i++)
{
if(score[i] < SCORE)
{
num++;
}
else
break;
}
printf("The count of students to fail is :%0.2f %%\n",100*(float)num/STU);
return 0;
}
用冒泡写感觉简单点.
再问: 加上输出不及格的人数
再答: #include #include #define STU 10 //宏定义学生人数,改起来方便 #define SCORE 60 //学生及格分数线 int main() { int score[STU]; int i; int j; int t; int num = 0; printf("please input ten number:"); for(i = 0; i < STU; i++) { scanf("%d",&score[i]); } for(i = 0; i < STU; i++) { for(j = 0; j < STU-1; j++) { if(score[j]>score[j+1]) { t = score[j]; score[j] =score[j+1]; score[j+1] = t; } } } printf("The high score is :%d\n",score[STU-1]); printf("The low score is :%d\n",score[0]); for(i = 0; i < STU; i++) { if(score[i] < SCORE) { num++; } else break; } printf("The count of students to fail is:%d\n",num); printf("The rate of students to fail is :%0.2f %%\n",100*(float)num/STU); return 0; }
 
 
展开全文阅读
剩余:2000
上一页:减术分裂
下一页:语文学习与巩固