Guest User

Untitled

a guest
Jan 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. /* 程式範例: Ch2-3-1.c */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. struct student { /* 學生資料 */
  6. int id;
  7. char name[20];
  8. int math;
  9. int english;
  10. int computer;
  11. char Class[10];
  12. int accounting;
  13. };
  14. /* 主程式 */
  15. int main() {
  16. struct student std1; /* 宣告結構變數 */
  17. struct student std2 = {2, "江小魚", 45, 78, 66,"資1"};
  18. struct student std3;
  19. struct student std4;
  20. int total;
  21.  
  22. strcpy(std1.clas,"資1");
  23. std1.id = 1; /* 指定結構變數的值 */
  24. strcpy(std1.name, "陳會安");
  25. std1.math = 78;
  26. std1.english = 65;
  27. std1.computer = 90;
  28. std1.accounting = 83;
  29. std3 = std2; /* 指定敘述 */
  30.  
  31. strcpy(std4.clas,"資1");
  32. std1.id = 4; /* 指定結構變數的值 */
  33. strcpy(std4.name, "王小明");
  34. std4.math = 70;
  35. std4.english = 66;
  36. std4.computer = 80;
  37. std4.accounting= 93;
  38.  
  39. /* 顯示學生資料 */
  40. printf("學號: %d\n", std1.id);
  41. printf("姓名: %s\n", std1.name);
  42. total = std1.math + std1.english + std1.computer+std1.accounting;
  43. printf("成績總分: %d\n", total);
  44. printf("--------------------\n");
  45. printf("學號: %d\n", std2.id);
  46. printf("姓名: %s\n", std2.name);
  47. total = std2.math + std2.english + std2.computer+std2.accounting;
  48. printf("成績總分: %d\n", total);
  49. printf("--------------------\n");
  50. printf("學號: %d\n", std3.id);
  51. printf("姓名: %s\n", std3.name);
  52. total = std3.math + std3.english + std3.computer+std3.accounting;
  53. printf("成績總分: %d\n", total);
  54. printf("--------------------\n");
  55. printf("學號: %d\n", std4.id);
  56. printf("姓名: %s\n", std4.name);
  57. total = std3.math + std4.english + std4computer+std4.accounting;
  58. printf("成績總分: %d\n", total);
  59. system("PAUSE");
  60. return 0;
  61. }
Add Comment
Please, Sign In to add comment