[圖解C] ex 6-3

// exercise 6-3: display the 2x5 array

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int score[2][5] = {{77, 85, 73, 64, 91}, {68, 89, 79, 94, 83}};
    int i, j;
   
    for (i=0 ; i<2 ; i++){
        if (i==0)
           printf("the scores of Class A: ");
        else
           printf("the scores of Class B: ");
       
        for (j=0 ; j<5 ; j++){
            printf("%d  ", score[i][j]);
            }
           
        printf("\n");
    }
    printf("==============================================\n");
   
    int ttScr;    // total score = ttScr
       
    for (i=0 ; i<2 ; i++){
        ttScr = 0;
        for (j=0 ; j<5 ; j++){
            ttScr += score[i][j];
        }
       
        if (i==0)
           printf("Total score of Class A is %d\n", ttScr);
        else
           printf("Total score of Class B is %d\n\n", ttScr);
    }
   
    system("pause");
    return 0;
}