#include <stdlib.h>
#include <string.h>
struct student { /* 學生資料 */
int id;
char name[20];
char class[10];
int math;
int english;
int computer;
int accounting;
};/* 主程式 */
int main() {
struct student std1; /* 宣告結構變數 */
struct student std2 = {2, "江小魚", "資一1",45, 78, 66,48};
struct student std3;
struct student std4;
int total;
std1.id = 1; /* 指定結構變數的值 */
strcpy(std1.class, "資一1");
strcpy(std1.name, "陳會安");
std1.math = 78;
std1.english = 65;
std1.computer = 90;
std1.accounting=65;
std3 = std2; /* 指定敘述 */
std4.id = 4; /* 指定結構變數的值 */
strcpy(std4.class, "資一1");
strcpy(std4.name, "林俊信");
std4.math = 38;
std4.english = 55;
std4.computer = 99;
std4.accounting=28;
/* 顯示學生資料 */
printf("學號: %d\n", std1.id);
printf("班級: %s\n", std1.class);
printf("姓名: %s\n", std1.name);
total = std1.math + std1.english + std1.computer+std1.accounting;
printf("成績總分: %d\n", total);
printf("--------------------\n");
printf("學號: %d\n", std2.id);
printf("班級: %s\n", std2.class);
printf("姓名: %s\n", std2.name);
total = std2.math + std2.english + std2.computer+std2.accounting;
printf("成績總分: %d\n", total);
printf("--------------------\n");
printf("學號: %d\n", std3.id);
printf("班級: %s\n", std3.class);
printf("姓名: %s\n", std3.name);
total = std3.math + std3.english + std3.computer+std3.accounting;
printf("成績總分: %d\n", total);
printf("--------------------\n");
printf("學號: %d\n", std4.id);
printf("班級: %s\n", std4.class);
printf("姓名: %s\n", std4.name);
total = std4.math + std4.english + std4.computer+std4.accounting;
printf("成績總分: %d\n", total);
system("PAUSE");
return 0;
}
評分: ★★★★☆
回覆刪除Great !