利用结构体计算每个学生的4门课程的平均分,将各科成绩及平均分输出到score.txt中...

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
typedef struct date
{
    int year;
    int month;
    int day;
}DATE;
typedef struct student
{
    long studentID;
    char studentName[20];
    char studentSex;
    DATE birthday;
    int score[4];
}STUDENT;
int main()
{
    FILE *fp;
    int i,j,sum[30];
    STUDENT stu[30] = {{100310121,"王刚",'M',{1991,5,19},{72,83,90,82}},
    {100310122,"李小明",'M',{1992,8,20},{88,92,78,78}},
    {100310123,"王力宏",'F',{1991,9,19},{98,72,89,66}},
    {100310124,"陈丽丽",'F',{1992,3,22},{87,95,78,90}}};
    if(fopen_s(&fp,"score.txt","w") != NULL)
    {    printf_s("get the word");
         system("pause");
        printf_s("Failure to open demo.txt! \n");
        exit(0);
    }
    for(i = 0;i < 4;i++)
    {
        sum[i] = 0;
        for(j = 0;j < 4;j++)
        {
            sum[i] = sum[i] + stu[i].score[j];
        }
        fprintf(fp,"%10ld%8s%3c%6d/%02d/%02d%4d%4d%4d%4d%6.1f\n",stu[i].studentID,
            stu[i].studentName,
        stu[i].studentSex,
        stu[i].birthday .year,
        stu[i].birthday.month,
        stu[i].birthday.day,
        stu[i].score[0],
        stu[i].score[1],
        stu[i].score[2],
        stu[i].score[3],
        sum[i]/4.0);
     }
    fclose(fp);
    system("pause");
    return 0;
}

 

转载于:https://www.cnblogs.com/joyclub/p/4436754.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值