zoukankan      html  css  js  c++  java
  • c 语言_二维数组_打印多行表格数据

    打印多行表格数据:

    #include "stdio.h"

    #define STD 30
    #define COURCE 3

    int input_num_score(long number[], int score[][3]){
    int n;
    printf("Please enter the total number of the students(n<30):");
    scanf("%d", &n);
    printf("Enter No. and score as: MT EN PH\n");
    for (int i = 0; i < n; ++i) {
    scanf("%ld", &number[i]);
    for (int j = 0; j < 3; ++j) {
    scanf("%d", &score[i][j]);
    }
    }
    return n;
    }
    void total(int n, int score[][3], int sum[], float aver[]){
    for (int i = 0; i < 3; ++i) {
    sum[i] = 0;
    for (int j = 0; j < n; ++j) {
    sum[i] += score[i][j];
    }
    aver[i] = (float)sum[i] / 3;
    }
    }
    void print_num_score(long number[], int score[][3], int sun[], float aver[], int n){
    printf("Result: \n");
    printf("Cource\t");
    for (int i = 0; i < n; ++i) {
    printf("%6ld\t", number[i]);
    }
    printf("SUM\tAVER\n");

    for (int i = 0; i < 3; ++i) {
    switch (i) {
    case 0:
    printf("\tMT\t");break;
    case 1:
    printf("\tEN\t");break;
    case 2:
    printf("\tPH\t");break;
    }
    for (int j = 0; j < n; ++j) {
    printf("\t%d\t", score[j][i]);
    }
    printf("%d\t%f\n", sun[i], aver[i]);
    }

    }
    int main(){
    int n;
    int sum[STD];
    float aver [STD];
    long number[STD];
    int score[STD][COURCE];
    n = input_num_score(number, score);
    total(n, score, sum, aver);
    print_num_score(number, score, sum, aver, n);
    return 0;
    }
  • 相关阅读:
    【NOIP16提高组】换教室
    【扬中集训Day6T1】 白日梦
    【POJ 1061】 青蛙的约会
    【扬中集训DAY5T1】 交换矩阵
    【USACO】 Balanced Photo
    【USACO】 Balanced Lineup

    POJ P3352 Road Construction 解题报告
    洛谷 P2783 有机化学之神偶尔会做作弊 解题报告
    洛谷 P2300 合并神犇 解题报告
  • 原文地址:https://www.cnblogs.com/chen-villagehead/p/15585127.html
Copyright © 2011-2022 走看看