结构体编程

【问题描述】C语言进行了5次阶段性测试,老师需要统计3位同学的总分,请你用结构体数组或结构体指针的知识帮忙补全代码,求出每一位同学的总分,然后输出。

输入:

1001 5 5 4 5 5

1002 4 4 4 4 4

1003 5 3 3 5 3

输出:

1001 24

1002 20

1003 19

#include  <stdio.h>
struct    STUDENT
{  
        int  id;                    //学号  
        int  score[5];          //5次成绩  
        int  total;                //总分  
};
struct    STUDENT    student[3],*pstu;
int  main()
{
        int  i;
        for(pstu=student;  pstu<student+3;  pstu++)
        {
                scanf("%d",&pstu->id);
                pstu->total=0;
                  //接下来输入每位同学的5次测验成绩,并求每一位同学5次测验的总和
        
        i = 0;
        while (i < 5)
        {
            scanf("%d", &pstu->score[i]);
            i++;
        }

        }
        for(pstu=student;  pstu<student+3;  pstu++)
        {
                printf("%d\t",pstu->id);                  
        //输出每一位同学的总分
        
        printf("%d", (pstu->score[0] + pstu->score[1] + pstu->score[2] + pstu->score[3] + pstu->score[4]));


        printf("\n");
        }
        return  0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值