• 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;
    }
  • 相关阅读:
    DOS 错误代码
    WINRAR 建立批处理备份文件
    clear.bat
    continue break
    播放dll中的wav声音
    BAT删除自身del 0
    bat 延时10秒自动关闭自己bat
    产生随机数
    RemoveDirZ.bat
    DELPHI中取整数的方法
  • 原文地址:https://www.cnblogs.com/chen-villagehead/p/15585127.html
Copyright © 2020-2023  润新知