<stdio.h>
void
main()
{
int
i,
n,
reno
float
score[30],
avr,
a,
b,
c
char
name[30][9]
for(i
=
0
i
<
30
i++)
{
printf("%d号的成绩:",
i+1)
scanf("%f",
&score[i])
if(score[i]
<
0)
break
printf("%d号的姓名:",
i+1)
scanf("%s",
name[i])
}
n
=
i
printf("统计不及格人数:\n")
reno
=
0
avr
=
0
for(i
=
0
i
<
n
i++)
{
if(
score[i]
<
60)
{
reno++
printf("%d,
%s\n",
i+1,
name[i])
}
avr
+=
score[i]
}
printf("不及格人数为%d\n\n",
reno)
printf("统计成绩在平均分及平均分之上的学生人数:\n")
avr
/=
nreno
=
0
for(i
=
0
i
<
n
i++)
{
if(score[i]
>=
avr)
{
reno++
printf("%d,
%s\n",
i+1,
name[i])
}
}
printf("成绩在平均分及平均分之上的学生人数为%d\n\n",
reno)
printf("统计各分数段的人数及所占百分比(分数段为<60,60~79,>=80):\n")
a
=
b
=
c
=0
for(i
=
0
i
<
n
i++)
{
if(score[i]
<
60)
a++
else
if(score[i]
>=
80)
c++
else
b++
}
printf("<60:\t%.1f%%\n60~79:\t%.1f%%\n>=80:\t%.1f%%\n",100*a/n,100*b/n,100*c/n)
}
#include<stdio.h>
#include<stdlib.h>
//定义一个学生结构体数组
struct Student{
int id
double score
}Student[100]
//记录实际导入学生个数
int len = 0
//求最高分
void getmax() {
int maxid = 0
double maxscore = -1
for (int i = 0i <leni++) {
if (Student[i].score >maxscore) {
maxscore = Student[i].score
maxid = Student[i].id
}
}
printf("班级最高分为:%.2lf学号是:%d\n", maxscore, maxid)
}
//求最低分
void getmin() {
int minid = 0
double minscore = 101
for (int i = 0i <leni++) {
if (Student[i].score <minscore) {
minscore = Student[i].score
minid = Student[i].id
}
}
printf("班级最低分为:%.2lf学号是:%d\n", minscore, minid)
}
//求总分
double getsum() {
double sum = 0
for (int i = 0i <leni++) {
sum += Student[i].score
}
return sum
}
//求平均分
double getave() {
double ave = 0
return getsum() / len
}
//导入学生信息
void input() {
int id = 0
double score = 0
while (1) {
printf("请输入学生学号:")
scanf_s("%d", &id)
if (id == -1) { break}
printf("请输入学生成绩:")
scanf_s("%lf", &score)
Student[len].id = id
Student[len].score = score
len++
}
printf("信息导入完毕!\n")
}
int main() {
input()
printf("全班总分为:%.2lf\n", getsum())
printf("全班平均分为:%.2lf\n", getave())
getmax()
getmin()
return 0
}
注:此代码运行于VS2017,如果在VC6.0中运行,可将scanf_s改成scanf
并且for(int i=0i<leni++){xxx}改成int i=0for(i=0i<leni++){xxx}即可正常运行
程序运行测试图如下:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)