Advertisement
kk258966

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

Dec 12th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  struct grade //定義grade的資料結構
  6.  {
  7.     int eng_s,math_s;      
  8.  };
  9.  
  10.  struct student //定義student的資料結構
  11.  {
  12.     int student_id;
  13.     char name[50];
  14.     struct grade score;  //定義1變數score,用到grade的資料結構      
  15.  };
  16.  
  17. struct student student1,student2,student3;
  18.  
  19. int main(void)
  20. {
  21.    
  22.     student1.student_id=10007142;
  23.     strcpy(student1.name,"臨例會");
  24.     student1.score.eng_s=80;
  25.     student1.score.math_s=90;
  26.    
  27.     student2.student_id=10007143;
  28.     strcpy(student2.name,"剪宏語");
  29.     student2.score.eng_s=85;
  30.     student2.score.math_s=80;
  31.    
  32.     student3.student_id=10007147;
  33.     strcpy(student3.name,"成宴如");
  34.     student3.score.eng_s=90;
  35.     student3.score.math_s=70;
  36.    
  37.     printf("學號         姓名      英文分數     數學分數      \n");
  38.     printf("\n================================================================\n");
  39.     printf("%d    %s  %8d%12d",student1.student_id,student1.name,student1.score.eng_s,student1.score.math_s);
  40.     printf("\n================================================================\n");
  41.     printf("%d    %s  %8d%12d",student2.student_id,student2.name,student2.score.eng_s,student2.score.math_s);
  42.     printf("\n================================================================\n");
  43.     printf("%d    %s  %8d%12d",student3.student_id,student3.name,student3.score.eng_s,student3.score.math_s);
  44.     printf("\n================================================================\n");
  45.     system("pause");
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement