当前位置:首页 » 存储配置 » 存储学号和三门课

存储学号和三门课

发布时间: 2024-10-22 10:47:09

㈠ 定义一个一维数组存储学生学号,二维数组存储学生姓名,二维数组存储学生三门课程成绩及总分

#include<stdio.h>

intmain()
{
intid[100],n,i=0,len;
charname[100][10];
intscore[100][4];
while(1)
{
printf("分别输入学生%d的学号、姓名、三门成绩 ",i+1);
printf("(学号输入负数结束输入):");
scanf("%d",&n);
if(n<0)
break;
id[i]=n;
scanf("%s%d%d%d",name[i],&score[i][0],&score[i][1],&score[i][2]);
score[i][3]=score[i][0]+score[i][1]+score[i][2];
if(i++==99)
break;
}
printf(" 您输入的学生信息为: ");
len=i;
for(i=0;i<len;i++)
printf("%d%s%d%d%d%d ",id[i],name[i],score[i][0],score[i][1],score[i][2],score[i][3]);
}

c语言程序设计编程题目:请 :编写完成对学生相关信息的要求:1.定义一个结构体类型student,其中包括三个成

#include <stdio.h>

#include <stdlib.h>

#define STU_NUM 10 /*宏定义学生的数量*/

struct student /*定义一个结构体用来存放学生学号、三门课成绩、总分及平均成绩*/

{

char stu_id[20]; /*学生学号;*/

float score[3]; /*三门课成绩;*/

float total; /*总成绩;*/

float aver; /*平均成绩;*/

};

/*排序用一个函数来实现*/

void SortScore(student *stu,int n)

{

student stud;

for(int i = 0; i < n-1; i++)

for(int j = i+1 ; j < n; j++)

{

if(stu[i].total < stu[j].total)

{

stud = stu[i];

stu[i] = stu[j];

stu[j] = stud;

}

}

}

int main( )

{

student stu[STU_NUM]; /*创建结构体数组中有10个元素,分别用来保存这10个人的相关信息。*/

/*输入这十个学生的相关信息*/

for(int i = 0; i<STU_NUM; i++)

{

printf("请输入第%d个学生的学号:",i+1);

scanf("%s",&stu[i].stu_id);

printf("输入第%d个学生的数学成绩:",i+1);

scanf("%f",&stu[i].score[0]);

printf("输入第%d个学生的英语成绩:",i+1);

scanf("%f",&stu[i].score[1]);

printf("输入第%d个学生的计算机成绩:",i+1);

scanf("%f",&stu[i].score[2]);

stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];

stu[i].aver = stu[i].total/3;

}

printf("\n");

SortScore(stu,STU_NUM);/*调用排序函数*/

/*输出排序后的各学生的成绩*/

for(i = 0 ; i < STU_NUM; i++)

{

printf("序号: %d\t",i);

printf("学号:%s\t",stu[i].stu_id);

printf("数学:%f\t",stu[i].score[0]);

printf("英语:%f\t",stu[i].score[1]);

printf("计算机:%f\t",stu[i].score[2]);

printf("平均成绩:%f\t",stu[i].aver);

printf("总分:%f\t",stu[i].total);

printf("\n\n");

}

return 0;

}

注:(源程序中主要标识符含义说明)

#define STU_NUM 10 /*宏定义学生的数量*/

struct student /*定义一个结构体用来存放学生学号、三门课成绩、总分及平均成绩*/

{

char stu_id[20]; /*学生学号;*/

float score[3]; /*三门课成绩;*/

float total; /*总成绩;*/

float aver; /*平均成绩;*/

}

热点内容
linux路由服务器 发布:2025-07-04 21:13:57 浏览:5
为什么蓝牙配对还要发送密码呢 发布:2025-07-04 21:12:49 浏览:618
服务器无硬件是什么意思 发布:2025-07-04 21:01:57 浏览:761
存储服务器的硬盘如何格式化 发布:2025-07-04 20:59:54 浏览:113
联想服务器的bmc叫什么 发布:2025-07-04 20:52:29 浏览:817
三星手机如何建文件夹 发布:2025-07-04 20:42:34 浏览:475
苹果11的摄像头是什么配置 发布:2025-07-04 20:32:20 浏览:59
plc编程入门视频 发布:2025-07-04 20:26:02 浏览:927
小米电视设置界面密码是多少 发布:2025-07-04 20:26:01 浏览:989
linux软件测试 发布:2025-07-04 20:12:40 浏览:274