njupt MOOC 第十章编程

1

学生平均成绩计算和输出(10分)

题目内容:

利用结构体数组保存不超过10个学生的信息,每个学生的信息包括:学号、姓名和三门课(高数、物理和英语 )的成绩和平均分(整型)。

编写程序,从键盘输入学生的人数,然后依次输入每个学生的学号、姓名和3门课的成绩

然后计算每个学生的平均分

最后按指定格式输出每个学生的平均分

输入格式:

先输入一个整数,表示学生个数

然后每行输入一个学生的信息:学号、姓名和高数、物理及英语成绩

输出格式:

输出每个学生的平均分.printf中请用格式控制串"The average score of the %dth student is %d.\n"

输入样例:

5

1001 Zhang 100 90 80

1002 Wu 93 90 98

1003 Zhu 89 88 87

1004 Hu 90 98 98

1005 Wang 90 98 97

输出样例:

The average score of the 1th student is 90.

The average score of the 2th student is 93.

The average score of the 3th student is 88.

The average score of the 4th student is 95.

The average score of the 5th student is 95.

时间限制:500ms内存限制:32000kb

参考

#include <stdio.h>
struct Student
{
    int ID;
    char name[20];
    int score[3];
};
typedef struct Student Student;
int input (Student []);
void Average (Student [],int len);                                                                  
int main()
{
    Student st[10];
    int num;
    num=input(st);
    Average(st,num);
    return 0;
}
int input(Student s[])
{
    int i,j,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%s",&s[i].ID,&s[i].name);
        for(j=0;j<=2;j++)
        {
            scanf("%d",&s[i].score[j]);
        }
    }
    return n;
}
void Average (Student s[],int len)
{
    int i,j;
    for(i=0;i<len;i++)
    {
        int ave=0;
        for(j=0;j<=2;j++)
            ave+=s[i].score[j];
        i++;
        ave=ave/3;
        printf("The average score of the %dth student is %d.\n",i,ave);
    i--;
    }

}

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值