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># define M6# define N6voidAveragefloata[m][n]);intMain () {inti,j,x,y,sum; floatb[m][n]={{1,98, the, $},{2,94, the, -},{3, -, the, -,},{4, the, -, -},{5, the, the, the}}; printf ("\tchinese\tmonth\tenglish\tsum\tave\n");    Average (b); X=0;  for(i=0;i<6; i++)    {        if(%6==0) {printf ("\ n"); }        if(i==5&&j==5) {printf ("\nave\t"); X++; }         for(j=0;j<6; j + +)        {            if(j==5) {printf ("%.2f\t", B[i][j]); X++; }            Else if(i==5)            {                if(j==0) {printf ("ave\t"); }                 for(y=1; y<=3; y++) {printf ("%.2f\t", B[i][y]); }                 Break; }            Else{printf ("%.0f\t", B[i][j]); X++; }        }    }return 0; }voidAveragefloatA[m][n]) {    inti,j,sum;  for(j=1;j<4; j + +) {sum=0;  for(i=0;i<5; i++) {sum+=A[i][j]; } a[5][j]=sum/5.0; }     for(i=0;i<5; i++) {sum=0;  for(j=1;j<4; j + +) {sum+=A[i][j]; } a[i][4]=sum; a[i][5]=sum/3.0; }    }

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

# include <stdio.h>intMain () {intm,i,j; printf ("Please enter the number of rows in the Phalanx \ n"); scanf ("%d",&m); DoubleA[m][m],x,c[m],d[m],diagonal1,diagonal2; X=1;  for(i=0; i<m;i++) {C[i]=0; D[i]=0; }     for(i=0; i<m;i++)    {         for(j=0; j<m;j++) {A[i][j]=x++; }    }     for(i=0; i<m;i++)    {         for(j=0; j<m;j++) {C[i]+=A[i][j]; D[J]+=A[i][j]; if(i==j) {Diagonal1+=A[i][j]; }            if(i+j==m-1) {Diagonal2+=A[i][j]; }        }    }         for(i=0; i<m;i++) {printf ("line%d and is%.0lf\n", i+1, C[i]); printf ("the and is%.0lf\n in column%d", i+1, D[i]); } printf ("two diagonal and respectively for%.0LF,%.0LF", diagonal1,diagonal2);return 0; }

1. Print the Yang Hui triangle in the following form (requires output 10 lines)

the Yang Hui triangle has the following characteristics: (1) The first column and the elements on the diagonal are all 1 (2) Except for the first column and the elements on the diagonal, the values of the other elements are the sum of the same column elements and the previous column elements on the previous line.         

# include <stdio.h>intMain () {inti,j,x,y,z,b,c,a[Ten][ One]={0}; a[0][4]=1; Y=1; Z=4;  for(i=0;i<Ten; i++)    {         for(j=0;j<Ten-i;j++)        {            if(j<Ten-i) {printf ("  "); }} C=Z;  for(x=0; x<y;x++) {printf ("%4d", A[i][c]); C++; } printf ("\ n"); Y++; b=0; if(y%2==0)        {             for(x=0; x<y+1; x + +) {A[i+1][z+b]=a[i][z-1+b]+a[i][z+b]; b++; }        }        Else{z--;  for(x=0; x<y+1; x + +) {A[i+1][z+b]=a[i][z+b]+a[i][z+1+b]; b++; }        }    }return 0; }

2. Monkey Choose King

A group of monkeys will choose the new Monkey King. The new Monkey King's choice is: Let n only the candidate monkeys in a circle, from a position from a sequence numbered 1~n. Starting from the 1th number, each round from 1 to report 3, where the report 3 of the monkeys are out of the circle, and then from the next close to a monkey start the same count. So constantly circulating, the last one left is chosen as the Monkey King. What is the original number of monkeys elected Monkey King?

Input Format: the input gives a positive integer n (≤1000) in a row.

output Format: prints the number of the selected monkey in a row.
# include <stdio.h># define M +intMain () {inti,n,n,x,y,z,m,a[m]={0}; printf ("Please enter the number of monkeys N (n<=1000): \ N"); scanf ("%d",&N); M=1;  for(i=0; i<n;i++) {A[i]=m++; } N=0; Y=1;  Do    {         for(i=0; i<n;i++)        {            if(a[i]!=-1)            {                if(y%3==0) {A[i]=-1; N++; } z=i; Y++; }        }        if(y<=3)        {             Break; }    } while(n-n!=1); printf ("%d", z+1);return 0; }

Experiment Summary:

1. The use of arrays in the program can not be out of bounds (beyond the definition of the array length);

2. Two-dimensional array can not be automatically wrapped in the output, you need to add a newline manually;

3. The output tabular data is suitable for two-dimensional arrays;

4. Variables are divided into arguments and formal parameters, and arguments can be arbitrarily called, but the parameters are not.

Tenth time Assignment

Related Article

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.