1 #ifndef __HEAD_H__ 2 #define __HEAD_H__ 3 #include <stdlib.h> 4 #include <string.h> 5 #include <stdio.h> 6 //声明学生数据类型 7 struct Student{ 8 char name[20]; 9 int age; 10 int score; 11 }; 12 void Input(struct Student s[],int n); 13 float Averg(struct Student s[],int n); 14 int Max(struct Student s[],int n); 15 void Bubble(struct Student s[],int n); 16 void Output(struct Student s[],int n);
1 #include "head.h" 2 int main(int argc,const char *argv[]) 3 { 4 struct Student s[5]; 5 Input(s,2); 6 printf("平均成绩是%.2f",Averg(s,2)); 7 Max(s,2); 8 Bubble(s,2); 9 Output(s,2); 10 return 0; 11 } 12 #include "head.h" 13 #include <stdio.h> 14 void Input(struct Student s[],int n) 15 { 16 for(int i=0;i<n;i++) 17 { 18 printf("输入姓名:"); 19 scanf("%s",s[i].name); 20 printf("输入年龄:"); 21 scanf("%d",&s[i].age); 22 printf("输入成绩:"); 23 scanf("%d",&s[i].score); 24 } 25 } 26 float Averg(struct Student s[],int n) 27 { 28 float sum=0; 29 for(int i=0;i<n;i++) 30 { 31 sum+=s[i].score; 32 } 33 return sum/n; 34 } 35 int Max(struct Student s[],int n) 36 { 37 int max,maxi; 38 for(int i=0;i<5;i++) 39 { 40 if(i==0) 41 { 42 max=s[i].age; 43 maxi=i; 44 } 45 if(s[i].age>max) 46 { 47 max=s[i].age; 48 maxi=i; 49 } 50 } 51 printf("最大年龄的全部信息:姓名;%s,年龄:%d,分数:%.2f",s[maxi].name,s[maxi].age,s[maxi].score); 52 } 53 void Bubble(struct Student s[],int n) 54 { 55 int i,j,t; 56 for(i=1;i<n;i++) 57 { 58 int count=0; 59 for(j=0;j<n-i;j++) 60 { 61 if(s[j].score>s[j+1].score){ 62 t=s[j]; 63 s[j]=s[j+1]; 64 s[j+1]=t; 65 count++; 66 } 67 } 68 if(count==0) 69 break; 70 } 71 } 72 void Output(struct Student s[],int n) 73 { 74 for(int i=0;i<n;i++) 75 { 76 printf("姓名%c 年龄%d 分数%d",s[i].name,s[i].age,s[i].score); 77 } 78 }
标签:分数,__,定义,int,void,Student,年龄,include,struct From: https://www.cnblogs.com/xj123/p/17157116.html