打印多行表格数据:
#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;
}