/* 程式範例: Ch2-3-3.c */
#include <stdio.h>
#include <stdlib.h>
/* 主程式 */
int main() {
struct test { /* 宣告結構 */
int math;
int english;
int computer;
int accounting;
};
typedef struct test score; /* 定義新型態 */
score joe, jane,john; /* 使用新型態變數宣告 */
joe.math = 80; /* 指定成員變數 */
joe.english = 85;
joe.computer = 83;
joe.accounting=74;
jane.math = 78; /* 指定成員變數 */
jane.english = 65;
jane.computer = 55;
jane.accounting=88;
john.math = 87; /* 指定成員變數 */
john.english = 56;
john.computer = 75;
john.accounting=83;
/* 顯示成績 */
printf("姓名: Joe\n");
printf("數學: %d\n", joe.math);
printf("英文: %d\n", joe.english);
printf("數學: %d\n", joe.computer);
printf("會計: %d\n", joe.accounting);
printf("=================\n");
printf("姓名: Jane\n");
printf("數學: %d\n", jane.math);
printf("英文: %d\n", jane.english);
printf("數學: %d\n", jane.computer);
printf("會計: %d\n", jane.accounting);
printf("=================\n");
printf("姓名: John\n");
printf("數學: %d\n", john.math);
printf("英文: %d\n", john.english);
printf("數學: %d\n", john.computer);
printf("會計: %d\n", john.accounting);
system("PAUSE");
return 0;
}
評分: ★★★★▲
回覆刪除Good Job !