Advertisement
kk258966

12/12 進階程式設計 練習三

Dec 12th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define size 100
  6.  
  7.  struct student
  8.  {
  9.     int student_id;
  10.     char name[50];
  11.     int score[20];      
  12.  };
  13.  
  14.  struct student s_grade[size];
  15.  
  16. int main(void)
  17. {
  18.     s_grade[1].student_id=10007142;
  19.     strcpy(s_grade[1].name,"臨例會");
  20.     s_grade[1].score[1]=80;
  21.     s_grade[1].score[2]=90;
  22.    
  23.     s_grade[2].student_id=10007143;
  24.     strcpy(s_grade[2].name,"剪宏語");
  25.     s_grade[2].score[1]=85;
  26.     s_grade[2].score[2]=80;
  27.    
  28.    
  29.     s_grade[3].student_id=10007147;
  30.     strcpy(s_grade[3].name,"成宴如");
  31.     s_grade[3].score[1]=90;
  32.     s_grade[3].score[2]=70;
  33.    
  34.     printf("土法煉鋼印出\n");
  35.     printf("學號         姓名      英文分數     數學分數      \n");
  36.     printf("\n================================================================\n");
  37.     printf("%d    %s  %8d%12d",s_grade[1].student_id,s_grade[1].name,s_grade[1].score[1],s_grade[1].score[2]);
  38.     printf("\n================================================================\n");
  39.     printf("%d    %s  %8d%12d",s_grade[2].student_id,s_grade[2].name,s_grade[2].score[1],s_grade[2].score[2]);
  40.     printf("\n================================================================\n");
  41.     printf("%d    %s  %8d%12d",s_grade[3].student_id,s_grade[3].name,s_grade[3].score[1],s_grade[3].score[2]);
  42.     printf("\n================================================================\n");
  43.    
  44.     printf("迴圈印出\n");
  45.     int i;
  46.    
  47.     for (i=1;i<=3;i++)
  48.     {
  49.            printf("%d    %s  %8d%12d",s_grade[i].student_id,s_grade[i].name,s_grade[i].score[1],s_grade[i].score[2]);
  50.            printf("\n================================================================\n");
  51.     }
  52.    
  53.     system("pause");
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement