c语言 5-11

1、

#include <stdio.h>

int main(void)
{
    int i, j, a[8][3] = {};
    puts("please input the scores of the students.");
    for(i = 0; i < 6; i++)
    {
        for(j = 0; j < 2; j++)
        {
            printf("a[%d][%d] = ", i, j); scanf("%d", &a[i][j]);
        }
    }
    puts("\nshow the matrix form.");
    for(i = 0; i < 6; i++)
    {
        for(j = 0; j < 2; j++)
        {
            printf("%4d", a[i][j]);
        }
        putchar('\n');
    }
    puts("\ncalculate the major sum.");
    for(i = 0; i < 6; i++)
    {
        for(j = 0; j < 2; j++)
        {
            if(j == 0)
                a[6][j] += a[i][j];
            else
                a[6][j] += a[i][j];
        }
    }
    for(i = 0; i < 7; i++)
    {
        for(j = 0; j < 2; j++)
        {
            printf("%4d", a[i][j]);
        }
        putchar('\n');
    }
    puts("\ncalculate the sum");
    for(i = 0; i < 7; i++)
    {
        for(j = 0; j < 2; j++)
        {
            a[i][2] += a[i][j];
        }
    }
    for(i = 0; i < 7; i++)
    {
        for(j = 0; j < 3; j++)
        {
            printf("%4d", a[i][j]);
        }
        putchar('\n');
    }
    printf("\nthe chisum = %d; chimean = %.2f \n", a[6][0], (double)a[6][0] / 6 );
    printf("the mathsum = %d; mathmean = %.2f \n", a[6][1], (double)a[6][1] / 6);
    putchar('\n');
    for(i = 0; i < 6; i++)
    {
        printf("the student.NO.%d sum is %d, mean is %.2f\n", i + 1, a[i][2], (double)a[i][2] / 2);
    }
    
    return 0;
}

#include <stdio.h>

int main(void)
{
    int i, j, a[6][3] = {0};
    puts("please input the scores.");
    for(i = 0; i < 6; i++)
    {
        for(j = 0; j < 2; j++)
        {
            printf("a[%d][%d] = ", i, j); scanf("%d", &a[i][j]);
        }
    }
    int chisum = 0;
    int mathsum = 0;
    for(i = 0; i < 6; i++)
    {
        chisum += a[i][0];
        mathsum += a[i][1];
    }
    for(i = 0; i < 6; i++)
    {
        for(j = 0; j < 2; j++)
        {
            a[i][2] += a[i][j];
        }
    }
    puts("===result===");
    printf("chisum = %d, chimean = %.2f\n", chisum, (double)chisum / 6);
    printf("mathsum = %d, mathmean = %.2f\n\n", mathsum, (double)mathsum / 6);
    
    for(i = 0; i < 6; i++)
    {
        printf("student.NO.%d: sum = %d, mean = %.2f\n", i + 1, a[i][2], (double)a[i][2] / 2);
    }
    return 0;
}

 

posted @ 2021-05-01 17:30  小鲨鱼2018  阅读(50)  评论(0编辑  收藏  举报