C语言编写小程序

216关注399浏览

展开全部
收起
2回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • Peyton

    93人对此回答表示赞同


    先给你看运行结果:
    Please Input Student No.1's Name,Score1,Score2,Score3,Score4:
    Miles 90 98 78 67
    Please Input Student No.2's Name,Score1,Score2,Score3,Score4:
    Kelly 89 77 77 66
    Please Input Student No.3's Name,Score1,Score2,Score3,Score4:
    Token 78 67 23 90
    Please Input Student No.4's Name,Score1,Score2,Score3,Score4:
    Uole 78 56 32 99
    Please Input Student No.5's Name,Score1,Score2,Score3,Score4:
    Tek 34 78 98 67

    Name SumScore
    Miles 333
    Kelly 309
    Token 258
    Uole 265
    Tek 277

    Course AverageScore
    1 73.80
    2 75.20
    3 61.60
    4 77.80

    Best Student
    Miles 333
    Press any key to continue

    代码:

    #include <stdio.h>

    struct Student
    {
    int iScore[4];
    char szName[32];
    int iSumScore;
    };

    void main()
    {
    int i,iCourse,BestID;
    int SumCourse[4]={0};//每门课的总分
    struct Student stu[5]={0}; //5名学生
    for (i=0;i<5;i++)
    {
    printf("Please Input Student No.%d's Name,Score1,Score2,Score3,Score4:\n",i+1);
    scanf("%s",stu[i].szName); //读取第i名学生的名字
    //读取第i名学生4门课的成绩
    for(iCourse=0;iCourse<4;iCourse++)
    {
    scanf("%d",&stu[i].iScore[iCourse]);
    stu[i].iSumScore+=stu[i].iScore[iCourse]; //第i名学生的成绩等于他每门课的成绩之和
    SumCourse[iCourse]+=stu[i].iScore[iCourse];//每门课的总分等于每个学生该门课成绩之和
    }
    }
    BestID=0;
    //输出每个学生的总分,并找出分数最高的学生
    printf("\nName\tSumScore\n");
    for (i=0;i<5;i++)
    {
    printf("%s\t%d\n",stu[i].szName,stu[i].iSumScore);
    if (stu[i].iSumScore > stu[BestID].iSumScore)
    BestID=i;
    }
    //输出每门课的平均成绩
    printf("\nCourse\tAverageScore\n");
    for (iCourse=0;iCourse<4;iCourse++)
    {
    printf("%d\t%.2f\n",iCourse+1,SumCourse[iCourse]*1.0/5);
    }
    //输出成绩最好的学生的名称和总分
    printf("\nBest Student\n");
    printf("%s\t%d\n",stu[BestID].szName,stu[BestID].iSumScore);
    }
    展开
    93
    0回复
    发布于 7年前

    评论(0)

    收起评论

  • Charles

    93人对此回答表示赞同

    #include<stdio.h>

    int main()
    {
    float a[5][4],aver[5]={0},sum[5]={0},high=0.0;
    char name[5][20];
    int i,j,k;
    for ( i = 0 ; i < 5 ; i++ )
    {
    printf("请输入第%d位学生的名字:",i+1);
    scanf("%s",name[i]);
    printf("请输入第%d位学生的成绩:",i+1);
    for ( j = 0 ; j < 4 ; j++ )
    {
    scanf("%f",&a[i][j]);
    sum[i] += a[i][j];
    }
    if ( sum[i] > high)
    {
    high = sum[i];
    k = i ;
    }
    }
    for ( i = 0 ; i < 4 ; i++ )
    {
    for ( j =0 ; j < 4 ; j++ )
    {
    aver[i] += a[j][i];
    }
    aver[i] /= 4;
    }
    printf("\n");
    for ( i = 0 ; i < 5 ; i++ )
    printf("%s的总分是:%.2f\n",name[i],sum[i]);
    printf("\n");
    for ( i = 0 ; i < 4 ; i++ )
    printf("第%d门课的平均分是:%.2f\n",i+1,aver[i]);
    printf("\n\n最高分是:%s,他的总分是:%.2f\n",name[k],sum[k]);
    printf("\n");
    }
    展开
    93
    0回复
    发布于 9年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部