zoukankan      html  css  js  c++  java
  • 利用结构体计算每个学生的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! 
    ");
            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
    ",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;
    }
  • 相关阅读:
    rabbitmq入门
    php7.2 安装redis扩展
    php安装扩展的几种方法
    yum安装php7.2
    相关报错
    [枚举]P1089 津津的储蓄计划
    [DFS]排列的生成
    [枚举]P1085 不高兴的津津
    [模拟]P1047 校门外的树
    [模拟]P1046 陶陶摘苹果
  • 原文地址:https://www.cnblogs.com/joyclub/p/4436754.html
Copyright © 2011-2022 走看看