鱼C论坛

 找回密码
 立即注册
查看: 1281|回复: 1

跪求大佬路过看一下

[复制链接]
发表于 2022-1-13 16:50:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 杨小九 于 2022-1-13 17:05 编辑

#include <stdio.h>
#include <string.h>
struct student
{
        char num[9];
        int score;
};
int main()
{       
        struct student stu[9]={{"n01",61},{"n02",54},{"n03",71},{"n04",91},{"n05",85},{"n06",78},{"n07",95},{"n08",87},{"n09",69}};
        int i,j;
        double average,sum=0;
        struct student t;
        printf("9 students:\n");
        for(i=0;i<9;i++)
                printf("%s,%d\n",stu[i].num,stu[i].score);
        printf("\n");
        for(j=0;j<8;j++)
                for(i=0;i<8-j;i++)
                        if(stu[i].score<stu[i+1].score)
                        {t=stu[i];stu[i]=stu[i+1];stu[i+1]=t;}
        printf("The student who have the highest score:%s,%d\n",stu[0].num,stu[0].score);
        for(i=0;i<9;i++)
        {sum=sum+stu[i].score;}
        average=sum/9;
        printf("The average score is:%lf\n",average);
                return 0;
}


       
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-1-14 10:44:10 From FishC Mobile | 显示全部楼层
本帖最后由 傻眼貓咪 于 2022-1-14 10:46 编辑

  1. #include <stdio.h>
  2. #include <string.h>

  3. struct student{
  4.         char name[20]; // 注意这里,这是名字字符数量,不是学生人数
  5.         int score;
  6. };

  7. int main(){
  8.         struct student stu[9] = {
  9.                 {"n01", 61}, {"n02", 54}, {"n03", 71},
  10.                 {"n04", 91}, {"n05", 85}, {"n06", 78},
  11.                 {"n07", 95}, {"n08", 87}, {"n09", 69}};
  12.        
  13.         int i, j, t, sum = 0; // 注意这里
  14.         double average;
  15.        
  16.         printf("9 students:\n");
  17.         for(i = 0; i < 9; i++)
  18.         printf("%s: %d\n", stu[i].name, stu[i].score); // 注意这里
  19.        
  20.         printf("\n");
  21.         for(i = 0; i < 8; i++)
  22.         for(j = i+1; j < 9; j++) // 注意这里
  23.         if(stu[i].score < stu[j].score) // 注意这里
  24.         {
  25.                 t = stu[i].score;
  26.                 stu[i].score = stu[j].score;
  27.                 stu[j].score = t;
  28.         }
  29.        
  30.         printf("The student who have the highest score is %s: %d\n", stu[0].name, stu[0].score);
  31.        
  32.         for(i = 0; i < 9; i++)
  33.         sum += stu[i].score; // 注意这里
  34.         average = sum/9.; // 注意这里
  35.        
  36.         printf("The average score is:%lf\n", average);
  37.        
  38.         return 0;
  39. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 02:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表