#include <stdio.h>
#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,"江小魚","會一2",45,78,66,88};
struct student std3;
struct student std4;
int total;
std1.id=1; //指定結構變數的值
strcpy(std1.name,"陳會安");
strcpy(std1.Class,"會一2");
std1.math=78;
std1.english=65;
std1.computer=90;
std1.accounting=56;
std3=std2; //指定敘述
std1.id=4; //指定結構變數的值
strcpy(std4.name,"李大毛");
strcpy(std4.Class,"會一2");
std4.math=68;
std4.english=85;
std4.computer=49;
std4.accounting=36;
printf("學號: %d\n", std1.id);//顯示學生資料
printf("姓名: %s\n", std1.name);
printf("班級: %s\n", std1.Class);
total=std1.math+std1.english+std1.computer+std1.accounting;
printf("成績總分: %d\n", total);
printf("--------------------\n");
printf("學號: %d\n", std2.id);
printf("姓名: %s\n", std2.name);
printf("班級: %s\n", std2.Class);
total=std2.math+std2.english+std2.computer+std2.accounting;
printf("成績總分: %d\n", total);
printf("--------------------\n");
printf("學號: %d\n", std3.id);
printf("姓名: %s\n", std3.name);
printf("班級: %s\n", std3.Class);
total=std3.math+std3.english+std3.computer+std3.accounting;
printf("成績總分: %d\n", total);
printf("--------------------\n");
printf("學號: %d\n", std4.id);
printf("姓名: %s\n", std4.name);
printf("班級: %s\n", std4.Class);
total=std4.math+std4.english+std4.computer+std4.accounting;
printf("成績總分: %d\n", total);
system("PAUSE");
return 0;
}
評分: ★★★★▲
回覆刪除Excellent !