C/C++教程

c语言 5-11

本文主要是介绍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;
}

 

这篇关于c语言 5-11的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!