Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 修改程式範例: Ch2-3-4.c 為Ch2-3-4e.c */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct test /* 考試成績的結構 */
- {
- int math;
- int english;
- int computer;
- };
- struct phone /* phone結構 */
- {
- char phone1[20];
- char phone2[20];
- };
- struct student /* 學生資料的結構 */
- {
- int id;
- char name[20];
- struct test score; /* 成績結構變數 */
- struct phone callno; /* 電話結構變數 */
- };
- int main() /* 主程式 */
- {
- struct student std1; /* 結構變數的宣告 */
- struct student std2 = {2, "江小魚", {45, 78, 66},{"0422195240","0911235678"}};
- int total;
- std1.id = 1; /* 指定結構變數的值 */
- strcpy(std1.name, "陳會安");
- std1.score.math = 78;
- std1.score.english = 65;
- std1.score.computer = 90;
- strcpy(std1.callno.phone1, "0491911680");
- strcpy(std1.callno.phone2, "0912123567");
- printf("學號: %d\n", std1.id); /* 顯示學生資料 */
- printf("姓名: %s\n", std1.name);
- printf("電話1: %s\n", std1.callno.phone1);
- printf("電話2: %s\n", std1.callno.phone2);
- total = std1.score.math + std1.score.english +
- std1.score.computer;
- printf("成績總分: %d\n", total);
- printf("--------------------\n");
- printf("學號: %d\n", std2.id);
- printf("姓名: %s\n", std2.name);
- printf("電話1: %s\n", std2.callno.phone1);
- printf("電話2: %s\n", std2.callno.phone2);
- total = std2.score.math + std2.score.english +
- std2.score.computer;
- printf("成績總分: %d\n", total);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment