C must recite 18 classical programs 1Output 9*9 recipes.There are 9 rows and 9 columns, I control row and j control column.* / # include "stdio.h" Main () {int i, j, result; For (i = 1; I < 10; I + +) {for (j = 1; J < 10; J ++) { Result=i*j; Printf ("% D *% D =% - 3D", i, j, result); /* - 3D means left alignment, accounting for 3 places*/ } Printf ("\ n");/* Change lines after each line*/ } System ("pause"); } 2Classical Question: /* There is a pair of rabbits. From the third month after birth, a pair of rabbits are born every month, and a pair of rabbits are born every month after the third month. If the rabbits are not dead, what is the total number of rabbits per month? The number of rabbits is 1,1,2,3,5,8,13,21....*/ Main () { Long F1, F2; Int i; F1=f2=1; For (i = 1; I < = 20; I + +) Printf ("% 12ld% 12ld", f1, f2); If (i%2==0) printf ("\n"); /* controls output, four lines per line*/ F1 = F1 + f2; /* The first two months add up to the third month.*/ F2 = F1 + f2; /* The first two months add up to the third month.*/ } } 3,/* Judge how many prime numbers there are between 101 and 200, and output all prime numbers and the number of prime numbers. Procedure analysis: the method of judging prime numbers: remove 2 to sqrt with one number, if it can be divisible, It means that the number is not prime, but prime instead.* / # include "math.h" Main () { Int m, i, k, H = 0, leap = 1; Printf ("\ n"); For (m = 101; m < = 200; m + +) {k=sqrt (m); For (i = 2; I < = k; I + +) If (m%i==0) {leap = 0; break;} If (leap) / * after the inner loop ends, leap remains 1, then M is prime.*/ Printf ("%-4d", m); h++; If (h%10==0) Printf ("\ n"); } Leap=1; } Printf (" nThe total is% D", h); System ("pause"); } 4If a number is exactly equal to the sum of its factors, it is called a "perfect number".For example, 6 = 1 + 2 + 3. Programming Find out all finishes within 1000.* / Main () { Static int k [10]; Int i, J, N, s; For (j = 2; J < 1000; j + +) { N=-1; S=j; For (i = 1; I < j; I + +) {if ((j%i)==0) {n++; S=s-i; K[n]=i; } } If (s==0) {printf ("% D is a wanshu:", j); For (i = 0; I < n; I + +) Printf ("% d,""K [i]); Printf ("% d n", K [n]); } } System ("pause"); } 5The function of the program under /* is to rotate an array of 4 * 4 counterclockwise and output 90 degrees, requiring random input of the original array data, and output the new array in four rows and four columns. Please complete the procedure in the blank.* / Main () {int a [4] [4], B [4] [4], i, j;/*a stores raw array data, B stores rotated array data*/ Printf ("input 16 numbers:"); /* Enter a set of data and store it in array a, then rotate it into array b.*/ For (i = 0; I < 4; I + +) For (j = 0; J < 4; j + +) {scanf ("% d", & a [i] [j]); B [3-j] [i] = a [i] [j]; } Printf ("array b:\ n"); For (i = 0; I < 4; I + +) {for (j = 0; J < 4; J ++) Printf ("% 6d", B [i] [j]); Printf ("\ n"); } System ("pause"); } 6,/* Programming Printing Right Angle Yang Hui Triangle*/ Main () {int i, j, a [6] [6]; For (i = 0; I < = 5; I + +) {a [i] [i] = 1; a [i] [0] = 1;} For (i = 2; I < = 5; I + +) For (j = 1; J < = i-1; j + +) A [i] [j] = a [i-1] [j] + a [i-1] [j-1]; For (i = 0; I < = 5; I + +) {for (j = 0; J < = i; J ++) Printf ("% 4d", a [i] [j]); Printf ("\n");} System ("pause"); } 7,/* Enter the scores of 3 students in 4 courses through keyboard. The average scores of each student and each course are calculated respectively. All grades are required to be placed in an array of four rows and five columns, with spaces between the same data input and carriage return for different people. The last column and the last row are the average scores of each student, the average scores of each course and the total average scores of the class.* / # include < stdio.h > # include < stdlib.h > Main () Float a [4] [5], sum1, sum2; Int i, J; For (i = 0; I < 3; I + +) For (j = 0; J < 4; j + +) Scanf ("% f", & a [i] [j]); For (i = 0; I < 3; I + +) {sum1=0; For (j = 0; J < 4; j + +) Sum1 + = a [i] [j]; A [i] [4] = sum1/4; } For (j = 0; J < 5; j + +) {sum2=0; For (i = 0; I < 3; I + +) Sum2 + = a [i] [j]; A [3] [j] = sum2/3; } For (i = 0; I < 4; I + +) {for (j = 0; J < 5; J ++) Printf ("% 6.2f", a [i] [j]); Printf ("\ n"); } System ("pause"); } 8,/* Perfect the program to output the input string in reverse order. For example, input windows and output swodniw.* / # include < string.h > Main () {char C [200], c1; Int i, J, K; Printf ("Enter a string:"); Scanf ("% s", c); K=strlen (c); For (i = 0, J = k-1; I < K /

docxDoc C must recite 18 classical programs

Professional Docs > Common > Other > Preview
10 Pages 0 Downloads 137 Views 3.0 Score
Tips: Current document can only be previewed at most page8,If the total number of pages in the document exceeds page 8,please download the document。
Uploaded by admin on 2019-10-15 12:04:22
Rate
You can enter 255 characters
What is my domain?( answer:www.45doc.com )
comments
  • No comments yet