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>#defineN 5#defineM 6#defineL 3intMain () {intI,j,sumi,sumii,flag; Doublescore[n][m]={{1, -, the, -},{2, the, the, the},{3, the, +, -},{4, the, the, the},{5, -, the, the}},average[l]={0}; printf ("average scores of Chinese maths English");  for(i=0;i<5; i++) {Sumi=0;  for(j=1;j<6; j + +) {Sumi+=Score[i][j]; } score[i][4]=Sumi; score[i][5]=(Double) sumi/3; }     for(i=0;i<5; i++)    {             for(j=0;j<6; j + +) {printf ("%. LF", Score[i][j]); } printf ("\ n"); } Flag=0;  for(j=1;j<4; j + +) {Sumii=0;  for(i=0;i<5; i++) {Sumii+=Score[i][j]; } Average[flag]=(Double) sumii/5; Flag++; } printf ("Average score");  for(i=0;i<3; i++) {printf ("%. LF", Average[i]); }    return 0;}

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

#include <stdio.h>#defineN 10#defineM 10intMain () {intseries[n][m]={{1,2,3},{4,5,6},{7,8,9}},i,j,sum1,sum2,sum3=0, sum4=0;  for(i=0;i<3; i++)    {         for(j=0;j<3; j + +) {printf ("%5d", Series[i][j]); } printf ("\ n"); }     for(i=0;i<3; i++) {sum1=0;  for(j=0;j<3; j + +) {sum1+=Series[i][j]; } printf ("line%d and is%d\n", i+1, SUM1); }     for(j=0;j<3; j + +) {sum2=0;  for(i=0;i<3; i++) {sum2+=Series[i][j]; } printf ("the and is%d\n in column%d", j+1, sum2); }     for(i=0;i<3; i++)    {         for(j=0;j<3; j + +)        {            if(j==i) {sum3+=Series[i][j]; }}} printf ("the sum of the diagonal from left to right is:%d\n", SUM3);  for(j=2; j>=0; j--)    {         for(i=0;i<3; i++)        {            if(i+j==2) Sum4+=Series[i][j]; }} printf ("from right to left diagonal and for:%d\n", SUM4); return 0;}

Experimental summary: At the beginning, I want to put the average score of the array and the total score directly stored, and finally directly output two-dimensional array, but then consider each subject

The average score needs to have Chinese characters hint, so it used a one-dimensional array, the format of Zishing annoying, I did not do the perpetual calendar of the additional problem, so some did not

Clue and then in order to look clearer, I put the average score without preserving the decimal place, uh, uh, pretty neat. But there was one thing quite funny, and I thought two

Dimension array output is the form of the table, the result is that I think more ...

Summary of Knowledge Points: 1. The assignment of two-d arrays is similar to one-dimensional arrays, but it should be noted that when defining a two-dimensional array, the length of the first dimension can be unspecified, but

The length of the second dimension cannot be saved.

A two-dimensional array in a 2.C language is stored on a row.

3.a[6][7]--> the first square bracket represents a row, and the second represents a column.

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.