zoukankan      html  css  js  c++  java
  • c语言中求课程总分、平均分。学生总分及平均分

    1、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j;
        int a[6][2];
        puts("please input the elements of the 6 * 2 matrix.");
        for (i = 0; i < 6; i++)
        {
            for (j = 0; j < 2; j++ )
            {
                printf("a[%d][%d] = ", i, j ); scanf("%d", &a[i][j]);
            }
        }
        int majorsum[2] = {0};
        int majormean[2];
        for (i = 0; i < 2; i++)
        {
            for (j = 0; j < 6; j++)
            {
                majorsum[i] += a[j][i]; 
            }
            majormean[i] = majorsum[i]/6;
        }
        for (i = 0; i < 2; i++)
        {
            printf("majorsum[%d] = %d\n", i, majorsum[i]);
            printf("majormean[%d] = %d\n", i, majormean[i]);
        }
        puts("--------\n--------\n---------");
        int studentsum[6];
        int studentmean[6];
        for (i = 0; i < 6; i++)
        {
            for (j = 0; j < 2; j++)
            {
                studentsum[i] += a[i][j];
            }
            studentmean[i] = studentsum[i]/2;
        }
        for (i = 0; i < 6; i++)
        {
            printf("studentsum[%d] = %d\n", i, studentsum[i]);
            printf("studentmean[%d] = %d\n", i, studentmean[i]);
        }
        return 0;
    }

     

    #include <stdio.h>
    
    int main(void)
    {
        int a[6][2];
        int i, j;
        puts("please input the elements of the 6 * 2 matrix.");
        for (i = 0; i < 6; i++)
        {
            for (j = 0; j < 2; j++)
            {
                printf("a[%d][%d] = ", i, j);
                scanf("%d", &a[i][j]);
            }
        }
        int majorsum[2] = {0};
        double majormean[2];
        for (i = 0; i < 2; i++)
        {
            for (j = 0; j < 6; j++)
            {
                majorsum[i] += a[j][i];
            }
            majormean[i] = majorsum[i]/6;
        }
        for (i = 0; i < 2; i++)
        {
            printf("majorsum[%d] = %d\n", i, majorsum[i]);
            printf("majormean[%d] = %.1f\n", i, majormean[i]);
        }
        puts("--------\n--------\n--------");
        int studentsum[6] = {};
        double studentmean[6];
        for (i = 0; i < 6; i++)
        {
            for (j = 0; j < 2; j++)
            {
                studentsum[i] += a[i][j];
            }
            studentmean[i] = studentsum[i]/2;
        }
        for (i = 0; i < 6; i++)
        {
            printf("studentsum[%d] = %d\n", i, studentsum[i]);
            printf("studentmean[%d] = %.1f\n", i, studentmean[i]);
        }
        
        return 0;
    }

  • 相关阅读:
    Java实现串口通信的小样例
    poi读写Excel
    java的list类
    java集合类
    常用正则表达式
    正则表达式
    Java获取路径中的文件名(正则表达式)
    poi读取word2003(.doc文档)中的表格
    使用poi读取word2007(.docx)中的复杂表格
    使用Maven搭建SpringMVC
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14381378.html
Copyright © 2011-2022 走看看