C language programming (2) design content 1, two table tennis teams compete, each team has 3 people. Team a is
C language classic 100 Question: Program 1 Question: With the number 1, 2, 3, 4, how many three digits can be formed without repetition? Program analysis: the number that can fill in hundreds, tens and units is 1 2. printf(" \ n "); for(I 1; I2)/* If it is a leap year and the month is greater than 2, the total number of days should be increased by one day */sum++; Printf ("Today is the% d day." ,sum); Program 5 Topic: Enter three integers X, Y and Z, please output these three numbers from small to large. 1. program analysis: we try to put the smallest number on x, and compare x and y first. If x>Y exchanges the values of x and y, and then compares x and z, if X >: Z exchanges the values of x and z, then x can be minimized. 2. Program source code: main(){intx, y, z, t; scanf("%d%d%d ",& ampx & amp; y & amp; z); if(x & gt; y){ tx; xy; yt; }/* Exchange the values of x and y */if (x >; z){ tz; zx; XT; }/* Exchange the values of x and z */if (y >; z){ ty; yz; ZT; }/* Exchange the values of z and y */printf ("smalltobig:% d% d \ n ",x, y, z); Title of program 6: output the pattern of letter c with *. 1. program analysis: you can first write the letter c on paper with' *' and then output it line by line. 2. Program source code: # include "stdio.h" main () {printf ("helloc-world! \ n "); printf(" * * * * \ n "); printf(" * \ n "); printf(" * \ n "); printf(" * * * * \ n "); } program 7 topic: output special patterns, please run it in C environment, it's very beautiful! 1. Program analysis: there are 256 characters * * *. Different roles have different graphics. 2. Program source code: # include "stdio.h" main () {chara176, b 219; printf("%c%c%c%c%c\n ",b,a,a,a,b); printf("%c%c%c%c%c\n ",a,b,a,b,a); printf("%c%c%c%c%c\n ",a,a,b,a,a); printf("%c%c%c%c%c\n ",a,b,a,b,a); printf("%c%c%c%c%c\n ",b,a,a,a,b); } Program 8 Topic: Output 9*9 formula. 1. Scheme analysis: consider branches and columns, * * 9 rows and 9 columns, I control line and J control column. 2. Program source code: # include "stdio.h" main () {inti, j, resultprintf(" \ n ");); for(I 1; Ib)a:b This is a basic example of a conditional operator. 2. Program source code: main () {intscore; chargradeprintf(" pleaseinputascore \ n "); Scanf("%d ",& score); Gradescore & gt90'a': (score & GT60' b':' c'); Printf("%dbelongsto%c ",score, grade); } program 15 topic: using the nesting of conditional operators to complete this topic: academic performance >; Students with 90 points are indicated by A, students with 60-89 points are indicated by B, and students with less than 60 points are indicated by C. 1. Program analysis: (a>b)? This is a basic example of a conditional operator. 2. Program source code: main () {intscore; chargradeprintf(" pleaseinputascore \ n "); Scanf("%d ",& score); gradescore & gt90? A': (Score & gt60? b ':' C '); Printf("%dbelongsto%c ",score, grade); } Program 16 Title: Enter two positive integers m and n and find their greatest common divisor and least common multiple. 1. Program analysis: using rolling division. 2. Program source code: main () {inta, b, num 1, num 2, temp printf ("pleaseinputwonumbers: \ n"); scanf("%d,%d ",& ampnum 1。 num 2); if(num 1 { temp num 1; num 1 num 2; num2temp} anum 1; Bnum2 and (b! 0)/* Use rolling division until b is 0 */{ tempa% b;; ab; btemp}printf("gongyueshu:%d\n ",a); Printf ("Gongbeishu: %d\n", num1* num 2/a); } Program 17 Title: Enter a line of characters and count the numbers of English letters, spaces, numbers and other characters respectively. 1. Program Analysis: Use the while statement, provided that the input character is not' \n'.2. Program source code: # include "stdio.h" main () {charint letters 0, space0, digit0, others 0 printf ("pleaseinputsomecharants \ n"); while((cgetchar())! \ n '){ if(c & gt; A' and amp & amp' a' and amp & /* The number of peaches on the first day is twice that on the second day plus1*/x2x1; Day-; }printf("thetotalis%d\n ",x 1); Title of program 22: Two table tennis teams each have three players to participate in the competition. Team A has three players, A, B and C, and Team B has three players, X, Y and Z. The competition list has been decided by drawing lots. Someone asked the players about the list of matches. A said not to compete with X, and C said not to compete with X and Z. Please make a program to find out the names of the players of the three teams. Program analysis.10000.00000003/* I is the opponent of A, J is the opponent of B, and K is the opponent of C */for(i'x); ia[j])minj; tema[I]; a[I]a[min]; A [minimum] project; }/* output data */printf(" after sorted \ n "); for(i0; iprintf("%5d ",a[I]); Program 38 Title: Find the sum of diagonal elements of a 3*3 matrix 1. Program analysis: use double for loop control to input a two-dimensional array, and then accumulate an [i][i] output. 2. Program source code: main () {float [3] [3], sum 0;; inti,j; printf(" pleaseinputrectangleelement:\ n "); for(i0; i50)again true; Elseagainfalse}}} Program 46 Title: Macro #define command exercise (1) Program source code: # include "stdio.h" # defineTrue1# definefase0 # definesq (x) (x) * (x) VoidMain () {int num inta gain 1; printf(" \ 40:programwillstopifinputvaluelesssthan 50。 \ n "); While (again) {printf ("\ 40: pleaseinputnumber > ); scanf("%d ",& ampnum); printf(" \ 40:Thesquareforthisnumberis % d \ n ",SQ(num)); if(num & gt; 50)again true; ElseagainFALSE}}} Program 47 Title: Macro # Define Command Exercise (2) Program source code: # include "stdio.h" # Define Exchange (a, b) {\/* If two clothes commands are allowed in the macro definition, you must add "\" */int; \ ta\ ab\ bt\ } void main(void){ intx 10; inty20printf(" x % d; y%d\n ",x,y); Exchange (x, y); printf(" x % d; y%d\n ",x,y); } program 48 title: macro #define command exercise (3) program source code: # define lag> # define may) x: y # define minimum (x, y) (x > y)y:xvoidmain(){inta 10,b20# ifdefmaxprintf(" \ 40:thelargeroneis % d \ n ",maximum(a,b)); #elseprintf("\40: The following is %d\n ",minimum value (a, b).