1. There are 5 students, each of whom has a test score of 3 courses in Chinese, maths and foreign languages. Programming statistics The total score and average scores of each student and the average score of all students in each section. Requires that the results be initialized in the program, and the result is output in tabular form.
#include <stdio.h>#defineN 40#defineM 40intIsum_row (intScore[][n],intn);intIsum_column (intScore[][n],intn);intMain () {intscore[m][n]={{ -,98, About},{ the, -, -},{ -, About, $},{ -, -, *},{ *, About, the}},sum[m][n]={0},ave,i,j,ii; printf ("School number \ t language \ t math \ t English t total score \ t average score \ n"); for(j=0; j<m;j++) {printf ("%d\t", j+1); for(i=0; i<n;i++) { if(score[j][i]==0) { Break; } printf ("%d\t", Score[j][i]); } printf ("%d\t", Isum_row (score,j)); printf ("%d\n", Isum_row (SCORE,J)/3); if(score[j+1][0]==0) Break; } printf ("average points \ t"); for(i=0;i<3; i++) {printf ("%d\t", Isum_column (score,i)/5); }}intIsum_row (intScore[][n],intN) { inti,sum=0; for(i=0; i<n;i++) {sum+=Score[n][i]; } returnsum;}intIsum_column (intScore[][n],intN) { inti,sum=0; for(i=0; i<m;i++) { if(score[i+1][0]==0) { Break; } Sum+=Score[i][n]; } returnsum;}
2. Seek the sum of the elements of each row, column, and diagonal of any square.
#include <stdio.h>#include<stdlib.h>#defineN 40intMain () {intmatrix[n][n]={0},i,j,sum,ia=0, ib=0, Ic,id; CharC; for(j=0; j<n;j++) {ia=0; for(i=0; i<n;i++) {scanf ("%d",&Matrix[j][i]); IA++; if(matrix[j][i]==0) Break; } fflush (stdin); printf ("do you want to enter the next line? "); IB++; if((C=getchar ()) = ='N'|| c=='N') Break; } System ("CLS"); for(j=0; j<n;j++) { for(i=0; i<n;i++) { if(matrix[j][i]==0) {printf ("\ n"); Break; } printf ("%2d", Matrix[j][i]); } if(matrix[j+1][0]==0) Break; } for(j=0; j<n;j++,sum=0) { for(i=0; i<n;i++) {sum+=Matrix[j][i]; } printf ("Line%d:", j+1); printf ("%d\n", sum); if(matrix[j+1][0]==0) Break; } for(j=0; j<n;j++) {sum=0; for(i=0; i<n;i++) {sum+=Matrix[i][j]; } printf ("column%d:", j+1); printf ("%d\n", sum); if(matrix[0][j+1]==0) Break; } for(i=0, sum=0; i<n;i++) {sum+ = (matrix[i][i]+matrix[i][ib-1-i]); } if(ia%2==0) {IC=ia/2; } Else{IC= (ia+1)/2; } if(ib%2==0) {ID=ib/2; } Else{ID= (ib+1)/2; } Sum=sum-Matrix[ic][id]; printf ("Diagonal and for%d\n", sum);}
Experiment Summary:
1, the first question is quite simple. But in order to look "general", still to write complex ...
2, the second question almost did not annoy me to die, just began to think is "Matrix", thought the irregular slope how to write ... Later realized that it was "phalanx" ...
3, lazy cancer, and did not write additional questions.
Teacher, don't hit me!!!!!!!!.
Tenth time Assignment