1. 程式人生 > >結構體的應用-成績錄入初步

結構體的應用-成績錄入初步

str truct 應用 include pri 初步 ++ pos ()

 1 #include<cstdio>
 2 #include<string>
 3 
 4 struct student{
 5     int num;
 6     char name[20];
 7     int score;
 8 };
 9 
10 int main(){
11     int i;
12     struct student st,stmax,stmin;
13     stmax.score = 0;
14     stmin.score = 100;
15     for(i=1;i<=100;i++){
16         scanf("
%d%s%d", &st.num, st.name, &st.score); 17 if(st.score > stmax.score) 18 stmax = st; 19 if(st.score < stmin.score) 20 stmin = st; 21 } 22 printf("\n %5d%15s%5d", stmax.num, stmax.name, stmax.score); 23 printf("\n %5d%15s%5d", stmin.num, stmin.name, stmin.score);
24 }

結構體的應用-成績錄入初步