#include <stdio.h> #define row 5 #define col 4 float sum(int n,int ary[row][col]); float average(int n,int ary[row][col]);
int main(void) { int i,j;
int score[row][col]= { {97,90,88,95}, {76,89,75,83}, {60,70,88,82}, {83,89,92,85}, {75,73,72,78} };
char name[row][10]={"이현수", "김기수", "김범용", "장기태", "이명수"};
printf("이름t중간1t중간2t기말1t기말2t합t평균n");
for(i=0; i<row; i++) { printf("%s ", name[i]); for(j=0;j<col;j++) { printf("%10d ", score[i][j] ); }
printf("%10lf %10lf n", sum(i, score), average(i, score)); puts("n"); } return 0; }
float sum(int i,int ary[row][col]) { int j; float total=0.0;
if(i==0) { for(j=2;j<col;j++) { total+=ary[i][j]; } } else if(i==1) { for(j=2;j<col;j++) { total+=ary[i][j]; } } else if(i==2) { for(j=2;j<col;j++) { total+=ary[i][j]; } } else if(i==3) { for(j=2;j<col;j++) { total+=ary[i][j]; } } else if(i==4) { for(j=2;j<col;j++) { total+=ary[i][j]; } } else { for(j=2;j<col;j++) { total+=ary[i][j]; } }
return total; }
float average(int i,int ary[row][col]) { int j; float total=0.0; float avg=0;
if(i==0) { for(j=2;j<col;j++) { total+=ary[i][j]; } avg = (float)total/4.0f; } else if(i==1) { for(j=2;j<col;j++) { total+=ary[i][j]; } avg = (float)total/4.0f; } else if(i==2) { for(j=2;j<col;j++) { total+=ary[i][j]; } avg = (float)total/4.0f; } else if(i==3) { for(j=2;j<col;j++) { total+=ary[i][j]; } avg = (float)total/4.0f; } else if(i==4) { for(j=2;j<col;j++) { total+=ary[i][j]; } avg = (float)total/4.0f; } else { for(j=2;j<col;j++) { total+=ary[i][j]; } avg = (float)total/4.0f; } return avg; }
|