Tenth time Assignment

Source: Internet
Author: User

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>intSumintscore[5][3],Doubleave[]);intMain () {intscore[5][3]={{Ten, -, -},{Ten, -, -},{Ten, -, -},{Ten, -, -},{Ten, -, -}}; inti,j,sum1,sum2,sum[5]; Doubleave1[5],ave2[3]; printf ("average scores of Chinese maths English");  for(i=0;i<5; i++) {sum1=0;  for(j=0;j<3; j + +) {sum1+=Score[i][j]; Sum[i]=sum1; } Sum[i]=sum1; Ave1[i]=(Double) sum1/3; }     for(j=0;j<3; j + +) {sum2=0;  for(i=0;i<5; i++) {sum2+=Score[i][j]; } Ave2[j]=(Double) sum2/5; }     for(i=0;i<5; i++) {printf ("First Class%d students", i+1);  for(j=0;j<3; j + +) {printf ("%d", Score[i][j]); } printf ("%d%.1f\n", Sum[i],ave1[i]); } printf ("Average score");  for(i=0;i<5; i++) {printf ("%.1f", Ave2[i]); } printf ("\ n"); return 0;}

2. Seek the sum of the elements of each row, column, and diagonal of any square.

# include <stdio.h># define M -intMain () {intI,j,m,sum1,sum2,sum3,sum4,sum[m][m]; printf ("the length of the input phalanx \ n"); scanf ("%d",&m);  for(i=0; i<m;i++) {printf ("Please enter the number in line%d: \ n", i+1);  for(j=0; j<m;j++) {scanf ("%d",&Sum[i][j]); }    }     for(i=0; i<m;i++) {sum1=0;  for(j=0; j<m;j++) {sum1+=Sum[i][j]; } printf ("line%d and is:%d\n", i+1, SUM1); }     for(j=0; j<m;j++) {sum2=0;  for(i=0; i<m;i++) {sum2+=Sum[i][j]; } printf ("the and of column%d is:%d\n", j+1, sum2); } sum3=0; SUM4=0;  for(i=0; i<m;i++) {sum3+=Sum[i][i]; SUM4+=sum[i][m-1-i]; } printf ("The sum of the diagonal is%d%d\n", SUM3,SUM4); return 0;}

Experimental conclusion: The storage of two-dimensional array is stored and output in the form of one-dimensional array;

Pay attention to the assignment value;

The subscript value should be within the range of the defined array size;

Notice that the array does not cross.

Tenth time Assignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.