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>#defineM 5#defineN 5intMain () {intb; Doublesum; DoubleGet5]={0},shu[m][n]={{ -, the, $},{ -, -, the},{94, About, the},{ the, +, About},{ the, -, the}}; printf ("\ t language \ t math \ t english \ t sum \ t average \ n"); for(a=0; a<m;a++) {sum=0; for(b=0; b<n-2; b++) {sum=sum+Shu[a][b]; } shu[a][3]=sum; shu[a][4]=shu[a][3]/(n2); } for(a=0; a<m;a++) {printf ("\ t"); for(b=0; b<n;b++) {printf ("%.2f\t", Shu[a][b]); } printf ("\ n"); } for(a=0; a<m;a++) {sum=0; for(b=0; b<n;b++) {sum=sum+Shu[b][a]; } He[a]=sum/N; } printf ("average \ t"); for(a=0; a<n;a++) {printf ("%.2f\t", He[a]); } return 0;}
2. Seek the sum of the elements of each row, column, and diagonal of any square.
#include <stdio.h>#defineM 3#defineN 3intMain () {inta[m][n]={{1,2,3},{1,2,3},{1,2,3}}; inti,j,hang1=0, hang2=0, hang3=0, lie1=0, lie2=0, lie3=0, zuoxie=0, youxie=0; for(i=0; i<n;i++) { for(j=0; j<m;j++) {printf ("%d", A[i][j]); } printf ("\ n"); } for(i=0; i<n;i++) {hang1=hang1+a[0][i]; Hang2=hang2+a[1][i]; Hang3=hang3+a[2][i]; Lie1=lie1+a[i][0]; Lie2=lie2+a[i][1]; Lie3=lie3+a[i][2]; Zuoxie=zuoxie+A[i][i]; Youxie=youxie+a[i][n-1-i]; } printf ("The first line is%d\n the second row is%d\n the third row is%d\n the first column is%d\n the second column is%d\n the third column is%d\n the left diagonal diagonal is%d\n right diagonal diagonal is%d\n", Hang1,hang2,hang3,lie1,lie2,lie3,zuoxie,youxie); return 0;}
Second, the experimental summary;
1. In a one-dimensional array of input and output, with a layer of loop to achieve, in the two-dimensional array of input and output, with a double-layer loop to achieve, with the outer loop to control the number of rows, the inner layer of the loop to control the number of columns.
2. Make a table with \ t, a \ t representing 4 characters.
3. In the loop, pay attention to whether to loop the rows first or to loop the columns first.
4. The array length of a row can be omitted in a two-D array, but the array length of the column cannot be omitted.
Tenth time Assignment