c语言编程题: 输入n个学生的姓名和百分制成绩,分段统计学生的成绩。

输入格式:
输入在第一行中给出正整数N(1≤n≤100)。随后N行,每行给出一位学生的姓名和成绩,中间以空格分隔。
输出格式:
在一行中顺序输出成绩为80-100分、60-79分、0-59分的学生人数,中间以空格分隔。
输入样例:
5
huanglan 83
wanghai 76
shenqiang 50
zhangfeng 95
zhangmeng 60
输出样例:
2 2 1
#include<stdio.h>
#define MAXN 100
struct student{
char name[20];
int score;
};
void cnt_score( struct student *p, int n );
int main()
{
int i, n;
struct student stu[MAXN];
scanf("%d", &n);
for(i = 0; i < n; i++){
scanf("%s%d", stu[i].name, &stu[i].score);
}
cnt_score(stu, n);
return 0;
}
void cnt_score(struct student *p, int n)
{
int cnt_a = 0, cnt_p = 0, cnt_f = 0;
(填空)
while ( p <= q ){
if (填空) cnt_a++;
else if (填空) cnt_p++;
else cnt_f++;
p++;
}
printf("%d %d %d\n", cnt_a, cnt_p, cnt_f);
}

第1个回答  2019-07-13
#include<stdio.h>
#define MAXN 100
struct student
{
char name[20];
int score;
};
void cnt_score( struct student *p, int n );
int main()
{
int i, n;
struct student stu[MAXN];
scanf("%d", &n);
for(i = 0; i < n; i++)
{
scanf("%s %d", stu[i].name, &stu[i].score);
}
cnt_score(stu, n);
return 0;
}
void cnt_score(struct student *p, int n)
{
int cnt_a = 0, cnt_p = 0, cnt_f = 0;
struct student *q=p+n-1;
while ( p <= q )
{
if ((*p).score>=80&&(*p).score<=100) cnt_a++;
else if ((*p).score>=60&&(*p).score<=79) cnt_p++;
else cnt_f++;
p++;
}
printf("%d %d %d\n", cnt_a, cnt_p, cnt_f);
}本回答被网友采纳