Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 2.74 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. struct student
  5. {   /* 學生資料 */
  6.     char Class[10];
  7.     int id;
  8.     char name[20];  
  9.     int math;
  10.     int english;
  11.     int computer;
  12.     int accounting;
  13. };
  14. /* 主程式 */
  15. int main()
  16. {
  17.    struct student std1;         /* 宣告結構變數 */  
  18.    struct student std2 = {"資一1", 2 , "江小魚" , 45 , 78 , 66 ,65};
  19.    struct student std3;
  20.    struct student std4;
  21.    int total;
  22.                      
  23.    strcpy(std1.Class, "資一1");      /* 指定結構變數的值 */
  24.    std1.id = 1;
  25.    strcpy(std1.name, "陳會安");
  26.    std1.math = 78;
  27.    std1.english = 65;
  28.    std1.computer = 90;
  29.    std1.accounting = 75;
  30.    
  31.    std3 = std2;     /* 指定敘述 */
  32.    
  33.    strcpy(std4.Class, "資一1");    /* 指定結構變數的值 */  
  34.    std4.id = 4;                
  35.    strcpy(std4.name, "張淑華");
  36.    std4.math = 80;
  37.    std4.english = 85;
  38.    std4.computer = 85;
  39.    std4.accounting = 75;
  40.    
  41.    /* 顯示學生資料 */
  42.    printf("班級: %s\n", std1.Class);
  43.    printf("學號: %d\n", std1.id);
  44.    printf("姓名: %s\n", std1.name);
  45.    printf("數學: %d\n", std1.math);
  46.    printf("英語: %d\n", std1.english);
  47.    printf("電腦: %d\n", std1.computer);
  48.    printf("會計: %d\n", std1.accounting);
  49.    total = std1.math + std1.english + std1.computer + std1.accounting;
  50.    printf("成績總分: %d\n", total);
  51.    printf("--------------------\n");
  52.    
  53.    printf("班級: %s\n", std2.Class);
  54.    printf("學號: %d\n", std2.id);
  55.    printf("姓名: %s\n", std2.name);
  56.    printf("數學: %d\n", std2.math);
  57.    printf("英語: %d\n", std2.english);
  58.    printf("電腦: %d\n", std2.computer);
  59.    printf("會計: %d\n", std2.accounting);
  60.    total = std2.math + std2.english + std2.computer + std2.accounting;
  61.    printf("成績總分: %d\n", total);
  62.    printf("--------------------\n");
  63.    
  64.    printf("班級: %s\n", std3.Class);
  65.    printf("學號: %d\n", std3.id);
  66.    printf("姓名: %s\n", std3.name);
  67.    printf("數學: %d\n", std3.math);
  68.    printf("英語: %d\n", std3.english);
  69.    printf("電腦: %d\n", std3.computer);
  70.    printf("會計: %d\n", std3.accounting);
  71.    total = std3.math + std3.english + std3.computer + std3.accounting;
  72.    printf("成績總分: %d\n", total);
  73.    printf("--------------------\n");
  74.    
  75.    printf("班級: %s\n", std4.Class);
  76.    printf("學號: %d\n", std4.id);
  77.    printf("姓名: %s\n", std4.name);
  78.    printf("數學: %d\n", std4.math);
  79.    printf("英語: %d\n", std4.english);
  80.    printf("電腦: %d\n", std4.computer);
  81.    printf("會計: %d\n", std4.accounting);
  82.    total = std4.math + std4.english + std4.computer + std4.accounting;
  83.    printf("成績總分: %d\n", total);
  84.    
  85.    system("PAUSE");
  86.    return 0;
  87. }