坐等!!!定义学生结构体类型,其成员包括学号、姓名、3门课的成绩 用一个函数input从键盘输入5个学生的

如题所述

代码如下:

#include <stdio.h>

#include  <string.h>

struct student {

long  sno;

char  name[10];

float  score[3];

};

void fun( struct student  *b)

{

b->sno = 10004;

strcpy(b->name, "LiJie");

}

main()

{struct student  t={10002,"ZhangQi", 93, 85, 87};

int  i;

printf("\n\nThe original data :\n");

printf("\nNo: %ld  Name: %s\nScores:  ",t.sno, t.name);

for (i=0; i<3; i++)  printf("%6.2f ", t.score[i]);

printf("\n");

fun(&t);

printf("\nThe data after modified :\n");

printf("\nNo: %ld  Name: %s\nScores:  ",t.sno, t.name);

for (i=0; i<3; i++)  printf("%6.2f ", t.score[i]);

printf("\n");

}


扩展资料

结构体内标的定义方式:

结构体,透明表区,DATA ELEMENT,DOMAIN

透明表是对一个物理表的逻辑描述,透明表里有许多字段,并且定义某些字段为 PRIMARY KEY,字段里又包含 DATA ELEMENT,用来描述语言属性和技术属性。DATA ELEMENT 中又包含 DOMAIN,它是定义数据类型和字段长度。

结构体一般是用来定义一个结构变量,有临时数据的储存,没有 PRIMARY KEY,结构体里包含 COMPONENT 而不是 FIELD

参考资料来源:

百度百科——结构体类型

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-11-02
#include "stdio.h"#include #define SIZE 5struct student{ char id[20]; char name[20]; int score[3];} stud[SIZE];float ave[SIZE];void input() /* 输入学生的信息 */{ int i; for(i=0;i<SIZE;i++) { printf("第%d个学生的信息:
",i+1); scanf("%s%s%d%d%d",stud[i].id,stud[i].name,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]); }}void average() /* 求每个学生的总平均分 */{ int i; for(i=0;i<SIZE;i++) { ave[i]=(stud[i].score[0]+stud[i].score[1]+stud[i].score[2])/3.0; }}void max() /* 找出总分最高学生的数据 */{int i,j;float ftemp; struct student temp; for(i=0;i<SIZE;i++) { for(j=0;j<SIZE-i-1;j++) { if(ave[j]<ave[j+1]) { temp=stud[j]; stud[j]=stud[j+1]; stud[j+1]=temp; ftemp=ave[j]; ave[j]=ave[j+1]; ave[j+1]=ftemp; } } } printf("
%s %s %d %d %d %3.1f
",stud[0].id,stud[0].name,stud[0].score[0],stud[0].score[1],stud[0].score[2],ave[0]);}void output() /* 输出学生的信息 */{ int i; printf("
"); for(i=0;i<SIZE;i++) printf("%s %s %d %d %d %3.1f
",stud[i].id,stud[i].name,stud[i].score[0],stud[i].score[1],stud[i].score[2],ave[i]);}void main(){ input(); average(); output(); max();}坐等!!!定义学生结构体类型,其成员包括学号、姓名、3门课的成绩 用一个函数input从键盘输入5个学生的本回答被提问者和网友采纳
相似回答