Guest User

Untitled

a guest
Jan 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. /* 修改程式範例: Ch2-3-4.c 為Ch2-3-4e.c */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. struct test /* 考試成績的結構 */
  6. {
  7. int math;
  8. int english;
  9. int computer;
  10. };
  11. struct phone /* phone結構 */
  12. {
  13. char phone1[20];
  14. char phone2[20];
  15. };
  16. struct student /* 學生資料的結構 */
  17. {
  18. int id;
  19. char name[20];
  20. struct test score; /* 成績結構變數 */
  21. struct phone callno; /* 電話結構變數 */
  22. };
  23.  
  24. int main() /* 主程式 */
  25. {
  26. struct student std1; /* 結構變數的宣告 */
  27. struct student std2 = {2, "江小魚", {45, 78, 66},{"0422195240","0911235678"}};
  28. int total;
  29. std1.id = 1; /* 指定結構變數的值 */
  30. strcpy(std1.name, "陳會安");
  31. std1.score.math = 78;
  32. std1.score.english = 65;
  33. std1.score.computer = 90;
  34. strcpy(std1.callno.phone1, "0491911680");
  35. strcpy(std1.callno.phone2, "0912123567");
  36. printf("學號: %d\n", std1.id); /* 顯示學生資料 */
  37. printf("姓名: %s\n", std1.name);
  38. printf("電話1: %s\n", std1.callno.phone1);
  39. printf("電話2: %s\n", std1.callno.phone2);
  40. total = std1.score.math + std1.score.english +
  41. std1.score.computer;
  42. printf("成績總分: %d\n", total);
  43. printf("--------------------\n");
  44. printf("學號: %d\n", std2.id);
  45. printf("姓名: %s\n", std2.name);
  46. printf("電話1: %s\n", std2.callno.phone1);
  47. printf("電話2: %s\n", std2.callno.phone2);
  48. total = std2.score.math + std2.score.english +
  49. std2.score.computer;
  50. printf("成績總分: %d\n", total);
  51.  
  52. system("PAUSE");
  53. return 0;
  54. }
Add Comment
Please, Sign In to add comment