Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 程式範例: Ch2-3-1.c */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct student { /* 學生資料 */
- int id;
- char name[20];
- int math;
- int english;
- int computer;
- char Class[10];
- int accounting;
- };
- /* 主程式 */
- int main() {
- struct student std1; /* 宣告結構變數 */
- struct student std2 = {2, "江小魚", 45, 78, 66,"資1"};
- struct student std3;
- struct student std4;
- int total;
- strcpy(std1.clas,"資1");
- std1.id = 1; /* 指定結構變數的值 */
- strcpy(std1.name, "陳會安");
- std1.math = 78;
- std1.english = 65;
- std1.computer = 90;
- std1.accounting = 83;
- std3 = std2; /* 指定敘述 */
- strcpy(std4.clas,"資1");
- std1.id = 4; /* 指定結構變數的值 */
- strcpy(std4.name, "王小明");
- std4.math = 70;
- std4.english = 66;
- std4.computer = 80;
- std4.accounting= 93;
- /* 顯示學生資料 */
- printf("學號: %d\n", std1.id);
- 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.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.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.name);
- total = std3.math + std4.english + std4computer+std4.accounting;
- printf("成績總分: %d\n", total);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment