當前位置:首頁 » 存儲配置 » 存儲學號和三門課

存儲學號和三門課

發布時間: 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; /*平均成績;*/

}

熱點內容
復制與文件夾合並 發布:2024-10-22 12:09:37 瀏覽:477
可編程數電 發布:2024-10-22 12:08:09 瀏覽:142
榮耀獵人筆記本哪個配置最適合買 發布:2024-10-22 11:31:00 瀏覽:377
excel文件加密器 發布:2024-10-22 11:24:09 瀏覽:792
我的世界伺服器點贊在哪裡看 發布:2024-10-22 11:24:09 瀏覽:736
geplc編程 發布:2024-10-22 11:18:21 瀏覽:348
查看linux安裝mysql 發布:2024-10-22 11:15:26 瀏覽:333
導入java代碼 發布:2024-10-22 11:13:14 瀏覽:974
雲伺服器不能復制到電腦 發布:2024-10-22 11:13:13 瀏覽:870
中國移動雲對象存儲 發布:2024-10-22 11:13:04 瀏覽:833