[Procedure 1] Title: There are 1, 2, 3, 4 numbers, how many three digits that are different from each other and no repeated numbers? What is it? 1. Program analysis: Fill in hundreds, ten, and bit numbers are 1, 2, 3, 4. After all arrangement, remove the arrangement of the conditions that do not satisfy the conditions. 2. Program source code: main () {INT I, J, K; Printf (n); for (i = 1; I5; i ) / below is a triple cycle for (j = 1; J5; J ) for (K = 1; K5; K ) {IF (i! = K && i! = J && j! = K) Make sure I, J, K three mutual NOI PRINTF (% D,% D,% DN, I, J, K); }} [Program 2] Title: The bonus issued by the company is submitted according to profit. When the profit (i) is less than or equal to 100,000 yuan, the bonus can be added 10%; the profit is higher than 100,000 yuan, less than 200,000 yuan, less than 100,000 yuan is added 10%, higher than 100,000 yuan. Part of the part, can be cocoa 7.5%; when 20,000 to 400,000, the part is higher than 200,000 yuan, it can be brought by 5%; between 400,000 and 600,000, it can be 3%. When 600,000 to 1 million, higher than 600,000 yuan, can be brought by 1.5%, higher than 1 million yuan, more than 1 million yuan, according to 1%, from the keyboard input the monthly profit I, seeking Total number of bonuses? 1. Program analysis: Please use the number axis to be bounded and positioned. Note that the bonus will be defined to grow. 2. Program source code: main () {Long Int i; int bonus1, bonus2, bonus4, bons6, bonus10, bons; scanf (% ld, & i); bonus1 = 1000000.1; bonus2 = Bonus1 1000000.75; bonus4 = Bonus2 2000000.5 Bonus6 = BONUS4 2000000.3; Bonus10 = Bonus6 4000000.15; if (i = 100000) Bonus = I0.1; Else IF (i = 200000) Bonus = Bonus1 (i-100000) 0.075; Else IF (i = 400000) Bonus = BONUS2 (I-200000) 0.05; Else IF (i = 600000) BONUS = BONUS4 (I-400000) 0.03; ELSE IF (i = 1000000) Bonus = Bonus6 (i-600000) 0.015; Else Bonus = Bonus10 (i- 1000000) 0.01; PRINTF (Bonus =% D, Bonus);} [Program 3] Title: A integer, it plus 100 is a complete square number, plus 168 is a complete square number, I would like this How many? 1. Program analysis: Judgment within 100,000, first plus 100, then open, then add 268, then reappear, if the result is satisfied, that is, the result.
Please see the specific analysis: 2. Source code: #include math.hmain () {long INT i, x, y, z; for (i = 1; i100000; i ) {x = SQRT (i 100); x In order to add the result of 100, Y = SQRT (i 268); Y is the result of the 1st after 168 after the opening of the 1st (xx == i 100 && yy == i 268) if a number of square roots The square is equal to the number, this indicates that this is a complete square printf (n% ldn, i);}} [program 4] topic: Enter a day of one month, judgment this day is the first day of this year ? 1. Program analysis: Take March 5 as an example, you should first add the first two months, then add 5 days, the first day, special circumstances, leap year, and enter the month to consider Add a day. 2. Program source code: main () {Int Day, month, year, sum, leap; printf (NPLEase Input Year, Month, Dayn); Scanf (% D,% D,% D, & Year, & Month, & Day); Switch (MONTH) first calculates the total number of days before the month {case 1-sum = 0; Break; case 2-sum = 31; Break; case 3-sum = 59; Break; case 4-sum = 90; Break; Case 5-SUM = 120; Break; Case 6-Sum = 151; Break; Case 7-Sum = 181; Break; Case 8-Sum = 212; Break; Case 9-Sum = 243; Break; Case 10-Sum = Break; Case 11-Sum = 304; Break; Case 12-Sum = 334; Break; default-printf (data error); Break;} SUM = SUM DAY; plus a day of days IF (Year% 400 == 0 (Year% 4 == 0 && Year% 100! = 0)) Judgment is the leap year leap = 1; Else Leap = 0; if (Leap == 1 && Month2) If it is a leap year and greater than 2, the total number of days should be added One day SUM ; Printf (IT is the% dth day., Sum);} [Program 5] Title: Enter three integers x, y, z, please put these three numbers from small to large output. 1. Program analysis: We want to put the smallest number into X, first compare X and Y, if XY exchanges X and Y value, then use x and z, if Xz will X is exchanged with the value of Z, which minimizes X. 2. Program source code: main () {Int x, y, z, t; scanf (% D% D% D, & x, & y, & z); if (xy) {t = x; x = y; y = T;} The value IF (xz) {t = z; z = x; x = T;}} = y; y = z; z = t; y; y = z; z = t; } Exchange Z, Y value Printf (Small to BIG% D% D% DN, X, Y, Z);} [Program 6] Title: Use the number to output the letter C. 1. Program analysis: You can write the letter C with `` number on the paper, and then output it.
2. Program source code: #include stdio.hmain () {Printf (Hello C-World! N); Printf (N); Printf (N); Printf (N); Printf (n);} [Program 7] Topic : Output special patterns, please run in the C environment, take a look, Very Beautiful! 1. Program analysis: Characters have a total of 256. Different characters, graphics are different. 2. Program source code: #include stdio.hmain () {char A = 176, b = 219; Printf (% C% C% C% C% CN, B, A, A, A, B); Printf (% C% C% C% C% C% CN, A, B, A, B, A); Printf (% C% C% C% C% CN, A, A, B, A, A); Printf (% C%) C% C% C% CN, A, B, A, B, A); Printf (% C% C% C% C% CN, B, A, A, A, B); [Program 8] Title: Output 99 mouth. 1. Program analysis: Branch and column considerations, a total of 9 rows, I control line, J control column. 2. Program source code: #include stdio.hmain () {INT I, J, RESULT; Printf (n); for (i = 1; i10; i ) {for (j = 1; j10; j ) {result = Ij; Printf (% D% D =% - 3D, I, J, Result); - 3D represents left alignment, accounting for 3 bits} printf (n); after each line, wrap}} [Program 9] Title: Require Output International Chess board. 1. Program analysis: Use the I control line, j to control the column, control the output black square according to the change in I J, or white square. 2. Program source code: #include stdio.hmain () {INT I, J; for (i = 0; i8; i ) {for (j = 0; J8; J ) IF ((i j)% 2 = = 0) Printf (% C% C, 219, 219); Else Printf (); Printf (N);}} [Program 10] Topic: Print the stairs, and print two smiles above the stairs. 1. Program analysis: Use the I control line, j to control the column, and the number of output black signs according to the change of I.
2. Source code: #include stdio.hmain () {INT I, J; Printf (11n); output two smiles for (i = 1; i11; i ) {for (j = 1; j = i; J PRINTF (% C, 219, 219); Printf (N);}} [program 11] Title: Classical question: There is a pair of rabbits, from the third month after birth, a bunny, small rabbit After growing to the third month, I have a bunny every month. If the rabbit is not dead, how much is the total number of rabbits every month? 1. Program analysis: Rabbit's laws are numbered 1, 1, 2, 3, 5, 8, 13, 21 .... 2. Data source code: main () {long f1, f2; int in; f1 = f2 = 1; for (i = 1; i = 20; i ) {Printf (% 12LD% 12LD, F1, F2); if (i% 2 == 0) Printf (n); control output, four F1 per line = F1 F2; add up to the third month of the third month F2 = F1 F2; the first two months added to the third month}} [program 12] topic: Judgment 101-200 How many of the individuals, and output all the numbers. 1. Program analysis: Method for judging the number of prime: Use a number to remove 2 to SQRT (this) 2. Program source code: #include math.hmain () {INT M, I, K, H = 0, Leap = 1; Printf (n); for (m = 101; m = 200; m ) {k = sqrt (m 1); for (i = 2; i = k; i ) IF (m% i == 0) {leap = 0; Break;} if (leap) {printf (% - 4d, m); h ; If (h% 10 == 0) PRINTF (N);} leap = 1;} Printf (NThe Total IS% D, H);} [Program 13] Title: Print all "Narcies", the so-called "Number of daffodils" refers to a three-digit number, and its digital cubes are equal to the number itself. For example: 153 is a "number of daffodils" because 153 = 1 triple square 5 three times. 1. Program analysis: Use the for loop to control 100-999 numbers, each number is broken down, ten, one hundred. 2. Program source code: main () {INT i, J, K, N; printf (`Water Flower`Number IS); for (n = 100; N1000; N ) {i = N100; Decompose hundreds of J = N10% 10; Decompose ten k = n% 10; decompose a bit IF (i100 j10 k == iii jjj kkk) {Printf (% - 5d, n);}} printf (n); } [Program 14] Title: Turn a positive integer to decompose the quality factor. For example: input 90, print 90 = 2335.
Program analysis: Differential factor of N, first find a minimum rigid number K, then complete: (1) If this number is just equal to N, the process of dividing factor is over, printing out . (2) If NK, but N can be divided by K, the value of K should be printed, and the NS is divided by K's business as a new positive integer you n, repeatedly performing the first step. (3) If N cannot be divided by K, use K 1 as a value of K, repeat the first step. 2. Program source code: zheng int is divided yinshumain () {INT N, I; Printf (NPLEase Input a Numbern); Scanf (% D, & N); Printf (% d =, n); for (i = 2; i = n; i ) {while (n! ==) {if (n% i == 0) {Printf (% D, I); n = ni;} else break;}} printf (% D, N) [Procedure 15] Title: Use the nested of the conditional operator to complete this question: Study score = 90 students use A. A representation of 60-89 points to B, 60, below, is expressed. 1. Program analysis: (ab) AB This is the basic example of the conditional operator. 2. Program source code: main () {int score; char grade; printf (please input a scoren; scanf (% d, & score); grade = score = 90`a, (score = 60`b``c `); Printf (% D Belongs TO% C, Score, grade);} [Program 16] Topic: Enter two positive integers M and N, ask for its maximum number of conventions and minimum common multiple. 1. Program analysis: Using the rolling method.
2. Program source code: main () {Int A, B, Num1, Num2, Temp; Printf (please input two numbern); scanf (% D,% D, & Num1, & number); if (num1num2) swaps two numbers Make a large number on Num1 {TEMP = Num1; Num1 = Num2; Num2 = Temp;} a = Num1; b = Num2; while (b! = 0) utilize rolling method until B is 0 {TEMP = a % B; a = b; b = Temp;} Printf (gongyueshu% DN, A); Printf (gongbeishu% DN, NUM1NUM2A);} [Program 17] Topic: Enter a line of characters, statistically in English letters, spaces, The number of numbers and other characters. 1. Program analysis: Use the While statement, the condition is not entered characters not `n` 2. Program source code: #include stdio.hmain () {char C; int letters = 0, space = 0, Digit = 0, Others = 0; Printf (please input some character "; while ((c = getchar ())! =` n`) {if (c = `a` && c =` z`c = `a` && c =` z` ) Letters ; else if (c == ``) Space ; else if (c = `0` && c =` 9`) Digit ; else Others ;} printf (all in allchar =% d Space =% D Digit =% D Others =% DN, Letters, Space, Digit, Others;} [Program 18] Title: S = A AA AAA AAAA AA ... A value, where A is a number. For example, 2 22 222 2222 22222 (there are 5 numbers at this time), and several numbers are added to the keyboard control. 1. Program analysis: The key is to calculate the value of each item. 2. Program source code: main () {Int a, n, count = 1; long int SN = 0, TN = 0; Printf (please input a and nn); scanf (% D,% D, & A, & n) PRINTF (A =% D, N =% DN, A, N); while (count = n) {TN = Tn a; SN = Sn TN; A = a10; count;} printf (A AA ... =% LDN, SN);} [Program 19] Title: A number is almost equal to its factor, this number is called "full". For example, 6 = 1 2 3. Programming Find all the completed within 1000.
1. Program analysis: Please refer to the program - Previous program 14. 2. Program source code: main () {static int K [10]; INT I, J, N, S; For (j = 2; J1000; J ) {N = -1; s = j; for (i = 1; Ij; i ) {IF ((j% i) == 0) {n ; s = Si; k [n] = i;}}} (s == 0) {Printf (% D is a wanshu, j); for (i = 0; in; i ) Printf (% D, k [i]); Printf (% DN, K [N]) }}} [Program 20] Title: One goal from 100 m high freedom, and half of the anti-jump back in the height of the anti-jump back; if it falls, how many meters have been elapsed in the 10th floor? How high is the 10th rebound? 1. Procedure analysis: See the comment below 2. Source code: main () {float Sn = 100.0, hn = SN2; INT N; for (n = 2; n = 10; n ) {SN = SN 2Hn; N-times-in-place mirase HN = HN2; Nth reverse hop height} Printf (The Tental of Road IS% FN, SN); Printf (The Tenth IS% F Metern, HN);} [Program 21] Topic: Monkey eats peach problem: The monkey took a few peaches on the first day, and immediately took half, but also didn't add addiction, and I ate a one-day, and I ate the remaining peach. I ate one. . Every morning, I ate half of the previous day. When I wanted to eat again on the 10th, I saw only one peach. How much is it taken on the first day. 1. Program analysis: Take the method of reverse thinking, inference from the past. 2. Program source code: main () {Int day, x1, x2; day = 9; x2 = 1; while (day0) {x1 = (x2 1) 2; the first day of the peach is the 2nd day 2x X2 = x1 after 1; day--;} Printf (The Total IS% DN, X1);} [Program 22] Title: Two table tennis teams have played three people. The broth is A, B, C, and the team is X, Y, Z. The list of matches have been drawn. Some people inquire to play the list of games. a said that he doesn't be with x, c says that he does not share the X, Z ratio, please compile the program to find the list of three teams. 1. Program analysis: Method for judging the number of prime: Use a number to remove 2 to SQRT (this)
2. Source code: main () {char i, j, k; i is a opponent, J is the opponent of B, K is the opponent for C (i = `x`; i =` z`; i ) For (j = `x`; j =` z`; j ) {if (i! = j) for (k = `x`; k =` z`; k ) {if (i! = k && j! = k ) {If (i! = `X` && k! =` X` &&k! = `Z`) Printf (Order IS A -% CTB -% CTC -% CN, I, J, K);}} }} [Program 23] Title: Print the right pattern
1. Program analysis: First divide the graphics into two parts, one regular, the last three lines, using a dual For cycle, the first layer control line, the second layer control column. 2. Program source code: main () {INT I, J, K; for (i = 0; i = 3; i ) {for (j = 0; j = 2-i; j ) printf (); for K = 0; k = 2i; k ) printf (); printf (n);} for (i = 0; i = 2; i ) {for (j = 0; j = i; j ) printf (); for (k = 0; k = 4-2i; k ) printf (); Printf (n);}} [program 24] Title: There is a score sequence: 21, 32, 53, 85, 138, 2113 ... seeking The sum of the first 20 items of this number. 1. Program analysis: Please seize the changes of molecular and denominator. 2. Program source code: main () {INT N, T, Number = 20; float a = 2, b = 1, s = 0; for (n = 1; n = number; n ) {s = s ab ; T = a; a = a b; b = t; this part is the key to the program, please reader guess T role} printf (SUM IS% 9.6fn, s);} [program 25] topic: see for 1 2! 3! ... 20! And 1. Program Analysis: This procedure only turns the accumulation into a tired. 2. Program source code: main () {float n, s = 0, t = 1; for (n = 1; n = 20; n ) {t = n; s = t;} printf (1 2! 3! ... 20! =% En, s);} [Program 26] Title: Use the recursive method to find 5! 1. Program analysis: recursive formula: Fn = fn_14! 2. Source code: #include stdio.hmain () {INT i; int fact (); for (i = 0; i5; i ) printf (40% D! =% DN, I, FACT (I));} INT FACT (J) INT J; {INT SUM; IF (J == 0) SUM = 1; Else Sum = JFACT (J-1); Return Sum;} [Program 27] Title: Use the recursive function call mode, 5 characters entered in the reverse order. 1. Program analysis: 2. Source code: #include stdio.hmain () {INT i = 5; Void palin (int N); Printf (40); Palin (i); printf (n);} void Palin N) int N; {char next; if (n = 1) {next = getChar (); printf (n0); putchar (next);} else {next = getchar (); palin (n-1); Putchar ( Next);}} [Program 28] Topic: There are 5 people sitting together, how old is the fifth person? He said that it is 2 years older than the 4th. Ask the fourth person, he said that it is 2 years older than the third person. Ask the third person, it is two years older than the second person. Ask the second person, saying that the first person is two years old. Finally, ask the first person, he said it was 10 years old.
How old is the fifth person? 1. Program analysis: Use the recursive method, recursion is divided into two phases of rebuilding and recursive. If you want to know the fifth person, you need to know the number of years of the fourth person, push it to the first person (10 years old), and then push it back. 2. Program source code: age (n) int N; {INT C; if (n == 1) c = 10; ELSE C = Age (N-1) 2; Return (C);}
Main () {printf (% D, AGE (5));} [Program 29] Title: Give one of the positive intensions of not more than 5, require: First, ask it is a few digits, second, reverse print out digital. 1. Program analysis: Learn to decompose each digit, as explained below: (Here is a simple algorithm, the number of ministers of the ministries) 2. Program source code: main () {long A, B, C , D, E, X; SCANF (% ld, & x); A = x10000; decompose 10,000 b = x% 100001000; decompose thousands C = x% 1000100; decompose hundreds of D = x% 10010; decomposition Ten ten E = x% 10; decompose IF (a! = 0) Printf (There Are 5,% LD% LD% LD% LD% LDN, E, D, C, B, A); ELSE IF (B! = 0) Printf (There Are 4,% LD% LD% LD% LDN, E, D, C, B); ELSE IF (C! = 0) Printf (TheRe Are 3,% LD% LD% LDN , E, D, C); ELSE IF (D! = 0) Printf (There Are 2,% LD% LDN, E, D); ELSE IF (E! = 0) Printf (There Are 1,% LDN, E );} [Program 30] Title: A 5 digits, it is determined that it is a number of copies. That is, 12321 is the number of times, the bit is the same, and ten is the same as the thousand. 1. Program analysis: same 29 cases 2. Program source code: main () {long ge, shi, qian, wan, x; scanf (% ld, & x); wan = x10000; qian = x% 100001000; shi = x % 10010; GE = X% 10; IF (GE == WAN && Shi == qian) is equal to 10,000 and ten is equal to thousands of Printf (This Number is a huiwenn; Else Printf (this number is not a huiwenn); } [Program 31] Title: Please enter the first letter of the day of the week to determine the week. If the first letter is the same, continue to judge the second letter. 1. Program analysis: Use the situation statement, if the first letter is the same, the judgment is determined by the case statement or the IF statement to determine the second letter.
2. Program source code: #include stdio.hvoid main () {char letter; printf (please input the first letter of somen); while ((Letter = getch ())! = `Y`) When the letter is Y End the {Switch (Letter) {CASE `S`-Printf (please Input Second Lettern); IF ((Letter = getCh ()) ==` a`) Printf (SaturDayn); Else IF ((Letter = getch () ) == `u`) PRINTF (SUNDAYN); Else Printf (Data ErrorN); Break; Case` F`-Printf (Fridayn); Break; Case `M`-Printf (Mondayn); Break; Case` t` Printf (PLEase Input Second Lettern); IF ((Letter = getch ()) == `u`) Printf (TuesdayN); Else IF ((Letter = getch ()) ==` h`) Printf (Thursday); Else Printf (Data Error); Break; Case `W`-Printf (WednesDayn); Break; Default Printf (Data ErrorN);}}} [Program 32] Title: Press Any Key To Change Color, Do you want to try it. Please hurry up! 1. Program analysis: 2. Program source code: #include conio.hvoid main (void) {Int Color; for (color = 0; color 8; color ) {textbackground (color); set text background color CPrintf (this is color% DRN, Color); CPrintf (Press any key to continueln); getch (); input character is invisible }}} [Program 33] Title: Learn gotoxy () and clrs () function 1. Program analysis: 2. Source code: #include conoe.hvoid main (void) {clrs (); clear screen function TextbackGround (2); Gotoxy (1, 5); positioning function CPRINTF (Output At Row 5 Column 1N); TextBackground (3); Gotoxxy (20, 10); CPrintf (Output At Row 10 Column 20N);} [Program 34] Title: Exercise Function Call 1. Program Analysis: 2. Program source code: #include stdio.hvoid hello_world (void) {Printf (Hello, World! N);} void three_hellos (void) {Int Counter; for (counter = 1; counter = 3 ; counter_world (); call this function} void main (void) {three_hellos (); call this function} [Program 35] Title: Text Color Settings 1. Program Analysis: 2. Source Code:
#include conio.hvoid main (void) {int color; for (color = 1; color 16; color ) {textcolor (color); set text color CPrintf (this is color% DRN, Color);} TextColor (128 15 CPRINTF (this is blinkingrn);} [program 36] Title: Question within 100 1. Program analysis: 2. Source code: #include stdio.h # include math.h # define n 101main () { INT I, J, LINE, A [N]; for (i = 2; IN; I ) a [i] = i; for (i = 2; isqRT (n); i ) for (j = i 1; JN; J ) {IF (a [i]! = 0 && a [j]! = 0) IF (a [j]% a [i] == 0) a [j] = 0;} printf (n); for (i = 2, line = 0; in; i ) {IF (a [i]! = 0) {Printf (% 5d, a [i]); line ;} if (line == 10) {printf (N ); line = 0;}}} [program 37] Title: Sort 10 numbers 1. Program analysis: You can use the selection method, that is, from the last 9 comparison process, select a minimum exchange with the first element exchange The next class push, that is, the second element is compared to the last 8, and exchange. 2. Program source code: #define n 10main () {INT i, J, min, TEM, A [N]; Input DataPrintf (PLEASE INPUT TEN NUMN); for (i = 0; in; i ) {printf (A [% D] =, i); scanf (% D, & a [i]);} printf (n); for (i = 0; in; i ) Printf (% 5d, a [i]); printf (n ); sort ten numfor (i = 0; in-1; i ) {min = i; for (j = i 1; jn; j ) IF (a [min] a [j]) min = j; TEM = a [i]; a [i] = a [min]; a [min] = Tem;} Output dataprintf (after sorted n); for (i = 0; in; i ) printf (% 5d, A [i] } [Program 38] Topic: Seeking a 33 matrix diagonal element and 1. Program analysis: Enter a two-dimensional array using dual for loop control, and then outputs A [I] [i]. 2. Program source code: main () {float a [3] [3], sum = 0; INT I, J; Printf (please infut rectangle elementn); for (i = 0; I3; i ) for (j = 0; J3; J ) scanf (% f, & a [i] [j]); for (i = 0; I3; i ) sum = sum a [i] [i]; printf (duijiaoxian HE IS% 6.2F , SUM);} [Program 39] Title: There is an array that has been ranked. Now enter a number, requiring it into an array as the original law.
1. Program analysis: First, it is determined whether the number is greater than the last number, and then considers the number of insertion the middle, the number after this element is inserted, and then moves one position in turn. 2. Program source code: main () {Int a [11] = {1, 4, 6, 9, 13, 16, 19, 28, 40, 100}; int TEMP1, TEMP2, NUMBER, END, I, J; Printf (Original Array ISN); for (i = 0; I10; I ) Printf (% 5d, A [I]); Printf (N); Printf (INSERT A NEW NUMBER); SCANF (% D, & Number); end = A [9]; if (numbered) a [10] = number; else {for (i = 0; i10; i ) {IF (a [i] number) {temp1 = a [i]; a [i] = Number; for (j = i 1; j11; j ) {temp2 = a [j]; a [j] = temp1; temp1 = TEMP2;} Break;}}} for (i = 0; i11; i ) Printf (% 6d, a [i]);} [program 40] topic: Output a array in reverse sequence. 1. Program analysis: Use the first exchange with the last one. 2. Program source code: #define n 5main () {int a [n] = {9, 6, 5, 4, 1}, i, temp; printf (n Original Arrayn); for (i = 0; in; i ) Printf (% 4d, A [i]); for (i = 0; in2; i ) {temp = a [i]; a [i] = a [Ni-1]; A [Ni-1] = Temp;} printf (n sorted arrayn); for (i = 0; in; i ) Printf (% 4d, a [i]);} [program 41] topic: Learn Static Define Static Variables Usage 1. Program Analysis: 2. Program source code: #include stdio.hvarfunc () {int var = 0; static int stat_var = 0; Printf (40Var Equal% DN, VAR); Printf (40-static var equivority DN, static_var); Printf n); var ; static_var ;} void main () {INT i; for (i = 0; I3; i ) varFunc ();} [program 42] Title: Learn to use auto definition variable usage 1. Program analysis: 2 . Source code: #include stdio.hmain () {INT i, NUM; NUM = 2; for (i = 0; I3; i ) {printf (40 the num equal% DN, NUM); Num ; {Auto INT Num = 1; Printf (40 The Internal Block Num Equal% DN, NUM); Num ;}}} [Program 43] Title: Learn another use of Static.
1. Program analysis: 2. Source code: #include stdio.hmain () {INT I, NUM; NUM = 2; for (i = 0; I3; i ) {printf (40 the num equal% DN, NUM) Num ; {static int num = 1; Printf (40the Internal Block Num Equal% DN, NUM); Num ;}}} [Program 44] Title: Learn to use External's usage. 1. Program analysis: 2. Source code: #include stdio.hint A, B, C; void add () {int A; a = 3; c = a b;} void main () {a = b = 4; add (); Printf (The value of c is equal to% DN, c);} [program 45] Topic: Learn how to use Register defined variables.
1. Program analysis: 2. Source code: void main () {register INT i; int TMP = 0; for (i = 1; i = 100; i ) TMP = I; Printf (The Sum IS% DN, TMP );} [Program 46] Title: Macro #define command exercises (1) 1. Program analysis: 2. Source code: #include stdio.h # define true 1 # define false 0 # define sq (x) (x) (X) void main () {Int Num; int Again = 1; Printf (40 Program Will Stop if INPUT VALUE LESS THAN 50.N); While (Again) {Printf (40please Input Number ==); scanf (% D , & num); Printf (40The Square for this Number IS% DN, SQ (NUM)); if (num = 50) again = true; else again = false;}} [program 47] topic: macro #define command exercise ( 2) 1. Program analysis: 2. Program source code: #include stdio.h # define Exchange (a, b) {Macro definition allows the case where two clothes commands are allowed, at this time, Int T must be added at the right right. T = a; a = b; b = T;} void main (void) {INT x = 10; int y = 20; Printf (x =% D; Y =% DN, X, Y); Exchange (X, y); Printf (x =% D; Y =% DN, X, Y);} [Program 48] Title: Macro #define command exercise (3) 1. Program analysis: 2. Source code: #define lag # Define sma #define EQ == # include stdio.hvoid main () {INT i = 10; int J = 20; if (i lag j) Printf (40% d Larger Than% DN, I, J); ELSE IF I EQ J) Printf (40% D Equal TO% DN, I, J); ELSE IF (I SMA J) Printf (40% DS Maller THAN% D N, I, J); ElsePrintf (40 no Such value.n);} [Program 49] Title: #if #ifdef and #ifndef integrated application.
1. Program analysis: 2. Program source code: #include stdio.h # define max # define maximum (x, y) (xy) xy # define minimum (x, y) (xy) yxvoid main () {int a = 10, B = 20; #ifdef maxprintf (40 the larder one IS% DN, Maximum (a, b)); # elseprintf (40 The Lower One IS% DN, Minimum (a, b)); # Endif # iFNDef MinPrintf (40 The Lower One IS% DN, Minimum (A, B)); # elseprintf (40 The Larger One I% DN, Maximum (A, B)); # Endif # undef Max # ifdef MaxPrintf (40 The Larger One IS % DN, Maximum (a, b)); # elseprintf (40 the Lower One I% DN, Minimum (a, b)); # Endif # Define MIN # ifndef minprintf (40 The Lower One IS% DN, Minimum (A , b)); # elseprintf (40 The Larger One IS% DN, Maximum (A, B)); # Endif} [Program 50] Title: #include App Exercise 1. Program Analysis: 2. Source Code: Test The file is as follows: #define lag #define sma #define eq == # include test.h A new file 50.c, containing Test.h # include stdio.hvoid main () {int i = 10; int J = 20 ; if (i lag j) Printf (40% d Larger Than% DN, I, J); ELSE IF (I EQ J) Printf (40% D Equal TO% DN, I, J); ELSE IF (I SMA J) PRINTF (40% D Smaller Than% DN, I, J); ElsePrintf (40 No Such value.n);} [Program 51] Title: Learning and uses bits and &. 1. Program analysis: 0 & 0 = 0; 0 & 1 = 0; 1 & 0 = 0; 1 & 1 = 12. Source code: #include stdio.hmain () {Int A, b; a = 077; b = a & 3; printf (40 the A & B (DECIMAL) IS% DN, B); B); B & = 7; Printf (40 The A & B (Decimal) IS% DN, B);} [Program 52] Title: Learn to use or. 1. Program analysis: 00 = 0; 01 = 1; 10 = 1; 11 = 1 2. Source code: #nclude stdio.hmain () {INT A, B; a = 077; b = a3; printf (40 The A & B (Decimal) IS% DN, B); B = 7; Printf (40 The A & B (Decimal) IS% DN, B);} [Program 53] Title: Learn to use and use or ^.
1. Program analysis: 0 ^ 0 = 0; 0 ^ 1 = 1; 1 ^ 0 = 1; 1 ^ 1 = 02. Source code: #nclude stdio.hmain () {Int A, b; a = 077; B = a ^ 3; Printf (40 the a & b (decimal) IS% DN, B); B ^ = 7; Printf (40 the A & B (Decimal) IS% DN, B);} [Program 54] Topic: Take an integer A from 4 to 7 from the right end. Program analysis: Can be considered: (1) First move a right 4 bits. (2) Set a number of low 4 digits to 1, the rest of the total is 0. The above is available for & computational uses ~ (~ 04) (3).
2. Program source code: main () {Unsigned A, B, C, D; Scanf (% O, & A); B = a4; c = ~ (~ 04); D = B & C; Printf (% ON% ON, A, D);} [Program 55] Topic: Learning and uses the bit by bit. 1. Program analysis: ~ 0 = 1; ~ 1 = 0; 2. Source code: #include stdio.hmain () {Int A, b; a = 234; b = ~ a; printf (40 the a`s 1 Complement (Decimal) IS% DN, B); A = ~ a; Printf (40 the a`s 1 Complement (HexideCIMAL) IS% XN, A);} [Program 56] Topic: Draw, learn Circle shape. 1. Program analysis: 2. Source code: Circle # include graphics.hmain () {Int Driver, Mode, i; float j = 1, k = 1; driver = VGA; Mode = Vgahi; Initgraph (& Driver, & Mode, ); setBkcolor (YELLOW); for (i = 0; i = 25; i ) {setColor (8); Circle (310, 250, k); k = k j; j = j 0.3;}} [program 57] Topic: Draw, learn line painting line. 1. Program analysis: 2. Program source code: #include graphics.hmain () {Int Driver, Mode, i; float x0, y0, y1, x1; float j = 12, k; driver = vga; mode = VGAHI; INITGRAPH (& Driver, & Mode); SetBkcolor (Green); x0 = 263; Y0 = 263; Y1 = 275; x1 = 275; for (i = 0; i = 18; i ) {setColor (5); line (x0 , Y0, X0, Y1); X0 = X0-5; Y0 = Y0-5; X1 = x1 5; Y1 = Y1 5; J = J 10;} X0 = 263; Y1 = 275; Y0 = 263 ; for (i = 0; i = 20; i ) {setColor (5); line (x0, y0, x0, y1); x0 = x0 5; Y0 = Y0 5; Y1 = Y1-5;}}} [Procedure 58] Title: Draw, learn Rectangle paintings. 1. Program analysis: Use the for loop to control 100-999 numbers, each number is broken down, ten, one hundred.
2. Program source code: #include graphics.hmain () {INT X0, Y0, Y1, X1, Driver, Mode, I; Driver = VGA; Mode = Vgahi; Initgraph (& Driver, & Mode,); setbkcolor (Yellow); X0 = 263; Y0 = 263; Y1 = 275; x1 = 275; for (i = 0; i = 18; i ) {setColor (1); Rectangle (X0, Y0, X1, Y1); X0 = X0-5 Y0 = Y0-5; X1 = x1 5; Y1 = Y1 5;} settextStyle (default_font, horiz_dir, 2); Outtextxy (150, 40, how beautiful it is!); line (130, 60, 480, 60) SetColor (2); Circle (269, 269, 137);} [Program 59] Topic: Draw, integrated example. 1. Program analysis: 2. Source code: # define pai 3.1415926 # Define b 0.809 # include graphics.h # include math.hmain () {Int i, j, k, x0, y0, x, y, driver, mode Float A; Driver = CGA; Mode = CGAC0; INITGRAPH (& Driver, & Mode); SetColor (3); setBkcolor (Green); x0 = 150; Y0 = 100; Circle (X0, Y0, 10); Circle (X0 , Y0, 20); Circle (X0, Y0, 50); for (i = 0; I16; I ) {A = (2PAI16) I; x = CEIL (X0 48COS (A)); Y = CEIL (Y0 48sin (a) b); setColor (2); line (x0, y0, x, y);} setColor (3); Circle (X0, Y0, 60); Make 0 Time Normal Size Letters setTextStyle (Default_Font, Horiz_Dir , 0); OUTTEXTXY (10, 170, Press A Key); getCH (); setch_fill, yellow; floodfill (202, 100, white); getCh (); for (k = 0; k = 500; k ) {setColor 3); for (i = 0; i = 16; i ) {a = (2PAI16) i (2PAI180) k; x = CEIL (x0 48cos (a)); y = CEIL (Y0 48 SIN (a ) B); setColor (2); line (x0, y0, x, y);} for (j = 1; j = 50; j ) {a = (2PAI16) i (2PAI180) k-1; x = ceil (X0 48COS (a)); y = CEIL (Y0 48SIN (a) b); line (x0, y0, x, y);}}}}} [program 60] Title: Draw, comprehensive example .
1. Program analysis: 2. Source code: #include graphics.h # define left 0 # define top 0 # define right 639 # define bottom 479 # define lines 400 # define maxcolor 15main () {int Driver, Mode, Error Download Admiral DEFINE MAXCOLOR INT X1, Y1; INT X2, Y2; INT DX1, DY1, DX2, DY2, I = 1; int count = 0; int color = 0; driver = VGA; Mode = Vgahi; Initgraph (& Driver, & Mode,); x1 = x2 = y1 = Y2 = 10; DX1 = DY1 = 2; DX2 = DY2 = 3; While (! kbhit ()) {line (x1, y1, x2, y2); x1 = DX1; Y1 = DY1; x2 = DX2; Y2 DY2; IF (x1 = leftx1 = Right) DX1 = -dx1; if (Y1 = TOPY1 = BOTTOM) DY1 = -DY1; if (x2 = leftx2 = Right) DX2 = -dx2; if (Y2 = TOPY2 = Bottom) DY2 =-Dy2; if ( countlines) {setColor (color); color = (color = maxColor) 0 color;}} closegraph ();} [program 61] Title: Print Yang Hui triangle ( Requires printing 10 lines as shown below) 1. Program analysis:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 2. Program source code: main () {INT I, J; INT A [10] [10]; Printf (n); For (i = 0; I10; i ) {a [i] [0] = 1; A [i] [i] = 1;} for (i = 2; i10; i ) for (j = 1; ji; J ) a [i] [j] = a [i-1] [j-1] a [i-1] [j]; for (i = 0; i10; i ) {for (j = 0; J = i; j ) Printf (% 5d, a [i] [j]); printf (n);}} [program 62] topic: Learn Putpixel paint point. 1. Program analysis: 2. Program source code: #include stdio.h # include graphics.hmain () {INT I, J, DRIVER = VGA, MODE = VGAHI; Initgraph (& Driver, & Mode,); setBkcolor (Yellow); For (i = 50; i = 230; i = 20) for (j = 50; j = 230; J ) PUTPIEL (I, J, 1); for (j = 50; j = 230; J = 20) for (i = 50; i = 230; i ) Putpixel (i, j, 1);} [program 63] Title: Draw Ellipse Ellipse 1. Program Analysis: 2. Source code: #nclude stdio.h # include graphics. H # include conoe.hmain () {int x = 360, y = 160, driver = VGA, MODE = Vgahi; int Num = 20, i; int top, bottom; initgraph (& driver, & model); top = Y- 30; bottom = Y-30; for (i = 0; inum; i ) {Ellipse (250, 250, 0, 360, TOP, BOTTOM); TOP- = 5; Bottom = 5;} getch ();} [program 64] topic : Use the Ellipse and Rectangle drawing. 1. Program analysis: 2. Source code: #include stdio.h # include graphics.h # include conio.hmain () {int DRIVER = VGA, MODE = Vgahi; Int i, num = 15, TOP = 50; int Left = 20, Right = 50; Initgraph (& Driver, & Mode); for (i = 0; Inum; i ) {Ellipse (250, 250, 0, 360, Right, Left); Ellipse (250, 250, 0, 360, 20, TOP); Rectangle (20-2i, 20-2i, 10 (i 2), 10 (i 2)); Right = 5; LEFT = 5; TOP = 10;} getCH ();} [program 65] Title: One most Beautiful pattern.
1. Program analysis: 2. Program source code: #include graphics.h # include Math.h # include dos.h # include cono.h # include stdlib.h # include stdio.h # include stdarg.h # define MaxPts 15 #define PI 3.1415926struct PTS {int x, y;}; double AspectRatio = 0.85; void LineToDemo (void) {struct viewporttype vp; struct PTS points [MAXPTS]; int i, j, h, w, xcenter, ycenter; int Radius, Angle, Step; Double Rads; Printf (MoveTo Lineto Demonstration); GetViewSettings; H = VP.BOTTOM - VP.TOP; W = VP.right - vp.Left; xceenter = W 2; DETERMINE THE CENTER OF Circle Ycenter = H 2; RADIUS = (H - 30); Step = 360 MaxPTS; DETERMINE # of increments Angle = 0; Begin At Zero Degrees for (i = 0; iMaxPts; i) {DETERMINE CIRCLE Intercepts Rads = (Double) Angle Pi 180.0; Convert Angle To Radians Points [i] .x = Xcenter (int) (in (RADS) RADIUS; Points [i] .y = ycenter - (int) (in (RADS) Radius aspectratio); angle = step; move to next increment}; Draw Bounding Circle for (i = 0; iMaxPts; i) {DR AW the cords to the circle for (j = i; jmaxpts; j) {for Each Remaining INTERSECT MOVETO (Points [i] .x, points [i] .y); move to beginning of cord lineto (Points [J) ] .X, Points [J] .y; Draw the Cord}}} main () {int DRIVER, MODE; DRIVER = CGA; MODE = CGAC0; Initgraph (& Driver, & Mode,); SetColor (3); setbkcolor Green); LinetODemo ();} [Program 66] Title: Input 3 numbers A, B, C, output in size order. Program analysis: Using the pointer method.
2. Program source code: Pointermain () {INT N1, N2, N3; Int Pointer1, Pointer2, Pointer3; Printf (please Input 3 Numbern1, N2, N3); Scanf (% D,% D,% D, & N1, & n2) , & n3); Pointer1 = & n1; Pointer2 = & n2; Pointer3 = & n3; if (n1n2) SWAP (Pointer1, Pointer2); if (N1N3) SWAP (Pointer1, Pointer3); if (N2N3) SWAP (Pointer2, Pointer3); Printf (The sorted number are% D,% D,% DN, N1, N2, N3);} SWAP (P1, P2) INT P1, P2; {INT P; P = P1; P1 = P2; P2 = P;} [Program 67] Title: Enter an array, the maximum exchange, the minimum exchange, and output an array with the last element. 1. Program analysis: There is a problem with the answer in Tan Haoqiang's book. 2. Program source code: main () {int number [10]; input (number); max_min (number); output (number);} INPUT (Number) int Number [10]; {INT i; for (i = 0; I9; I ) scanf (% D, & number [i]); scanf (% D, & number [9]);} Max_min (array) int Array [10]; {Int Max, min, k, L; INT P, Arr_end; Arr_END = Array 10; Max = min = array; for (p = array 1; parr_end; p ) IF (pmax) max = p; else if (pmin) min = p; k = max; L = min; p = array [0]; array [0] = L; L = P; p = array [9]; array [9] = k; k = p; return;} Output (array) int Array [ 10]; {INT P; for (p = array; parray 9; p ) Printf (% D, P); Printf (% DN, Array [9]);} [program 68] Title: N integers Make the number of each other in front of each of the previous numbers, and the last M number becomes the most in front of M number 1. Program analysis: 2. Source code: main () {int number [20], n, m , I; Printf (The Total Numbers IS); Scanf (% D, & N); Printf (BACK M); Scanf (% D, & M); for (i = 0; in-1; i ) scanf (% D, , & number [i]); scanf (% D, & number [N-1]); Move (Number, N, M); for (i = 0; in-1; i ) Printf (% D, Number [i ]); Printf (% D, Number [N-1]);} Move (Array, N, M) INT N, M, Array [20]; {INT P, Array_END; Array_END = (Array N-1) For (p = array n-1; parray; p -) p = (p-1); array = array_end; m -; if (m0) move (array, n, m);} [program 69 】 Title: There are n individuals into a circle, sequentially sorting.
From the first person to the number (from 1 to 3), people who reported 3 exited the circle and asked the last one of the best numbers. 1. Program analysis: 2. Source code: #define nmax 50mAin () {INT i, k, m, n, num [nmax], p; printf (please infut the total of number); scanf (% D, & n ); p = Num; for (i = 0; in; i ) (p i) = i 1; i = 0; k = 0; m = 0; While (Mn-1) {IF ((p I)! = 0) k ; if (k == 3) {(p i) = 0; k = 0; m ;} i ; if (i == n) i = 0;} while (p == 0) P ; Printf (% D IS LEFTN, P);} [Program 70] Topic: Write a function, ask a string length, enter a string in the main function, and output its length. 1. Program analysis: 2. Program source code: main () {int LEN; char STR [20]; Printf (please input a stringn); scanf (% s, str); len = length (str); printf (the String has% D characters., len);} length (p) char p; {int N = 0; while (p! = `0`) {n ; p ;} return n;} program 71] topic: Write the input () and output () function input, output 5 student's data records. 1. Program analysis: 2. Source code: #define n 5struct student {char Num [6]; char name [8]; int score [4];} stu [n]; input (stu) Struct Stud Station Stu [] ; {INT I, J; For (i = 0; in; i ) {printf (n please input% D OF% DN, i 1, n); Printf (NUM); scanf (% s, STU [i] .num); Printf (Name); scanf (% s, stu [i] .name); for (j = 0; J3; J ) {printf (score% d., j 1); scanf (% D, & stu [i] .score [j]);} Printf (n);}} Print (stu) struct student stu []; {INT I, J; Printf (nno. Name sco1 sco2 sco3n); for (i = 0 ; I ) {Printf (% - 6S% -10S, STU [i] .Num, STU [i] .Name); for (j = 0; J3; J ) Printf (% - 8D, STU [i] . Score [J]); Printf (n);}} main () {INPUT (); print ();} [program 72] Title: Create a list.
1. Program analysis: 2. Program source code: Creat a list # incrude stdlib.h # include stdio.hstruct list {int Data; struct list next;}; type; {link; void main () {link PTR, Head; Int Num, I; PTR = (LINK) Malloc (Sizeof (Node)); PTR = HEAD; Printf (please input 5 numbers == n); for (i = 0; i = 4; i ) { Scanf (% D, & NUM); PTR-DATA = NUM; PTR-NEXT = (LINK) Malloc (SizeOf (Node)); if (i == 4) PTR-NEXT = NULL; ELSE PTR = Ptr_} Ptr = head; while (ptr! = null) {printf (the value is ==% DN, PTR = Ptr-next;}} [program 73] Title: Reverse output a linked list. 1. Program analysis: 2. Source code: Reverse output a list # incrude stdlib.h # include stdio.hstruct list {int Data; struct list next;}; type;}; type; Link PTR, Head, Tail; Int Num, I; Tail = (LINK) Malloc (Sizeof (Node)); tail-next = null; Ptr = Tail; Printf (NPLEase INPUT 5 DATA == N); for (i = 0; i = 4; i ) {scanf (% D, & num); ptr-data = Num; head = (limited) malloc (sizeof (node)); head-next = ptr; ptr = head;} PTR = Ptr = Ptr -next; while (PTR! = NULL) {Printf (the value is ==% DN, PTR-data); PTR = Ptr-next;}} [program 74] Title: Connect two linked lists.
1. Program analysis: 2. Source code: #include stdlib.h # include stdio.hstruct list {int Data; struct list next;}; typef struct list node; typedef node link; link delete_node (link Pointer, Link TMP) {IF (TMP == Null) delete first node return Pointer-Next {IF (tmp-next-next == null) delete last node tmp-next = null; else delete the other node tmp-next = tmp-next -next;}}}}} void selection_sort (link pointer, int num) {link TMP, BTMP; INT i, min; for (i = 0; inum; i ) {TMP = Pointer; min = tmp-data; btmp = NULL; while (tmp-next) {IF (mintmp-next-data) {min = tmp-next-data; btmp = tmp;} TMP = tmp-next;} printf (40% DN, min); Pointer = DELETE_NODE (POINTER, BTMP);}} link create_list (int Array [], int Num) {link TMP1, TMP2, POINTER; INT I; Pointer = (LINK) Malloc (Sizeof (Node)); Pointer-Data = array [ 0]; TMP1 = POINTER; for (i = 1; inum; i ) {TMP2 = (link) malloc (sizeof (node)); TMP2-next = null; tmp2-data = array [i]; tmp1-next = TMP2; TMP1 = TMP1-Next;} Return Pointer;} Link Concatenate (Link Pointer1, Link Pointer2) {Link Tmp; TMP = Pointer1; While (Tmp-next) TMP = Tmp-next; TMP -next = Pointer2; Return Pointer1;}
Void main (void) {int Arr1 [] = {3, 12, 8, 9, 11}; link PTR; PTR = CREATE_LIST (Arr1, 5); Selection_Sort (PTR, 5);} [Program 75] Title: Relax Let's count a simple topic. 1. Program analysis: 2. Source code: main () {INT i, n; for (i = 1; i5; i ) {n = 0; if (i! = 1) n = n 1; IF ( i == 3) n = n 1; if (i == 4) n = N 1; if (i! = 4) n = n 1; if (n == 3) Printf (zhu hao shi de SHI% C, 64 I);}}} [program 76] Topic: Write a function, enter N is an even number, call the function request 12 14 ... 1n, when entering N is odd, call function 11 13 ... 1N (utilization pointer function) 1. Program analysis: 2. Source code: main () # include stdio.hmain () {float peven (), podd (), dcall (); float sum ; int N; while (1) {scanf (% D, & n); if (n1) Break;} if (n% 2 == 0) {Printf (Even =); sum = dcall (peven, n);} Else {Printf (odd =); sum = dcall (podd, n);} printf (% f, sum);} float peven (int N) {float s; int i; s = 1; for (i = 2; i = N; i = 2) S = 1 (float) i; return (s);} float podd (n) int N; {float s; int i; s = 0; for (i = 1; i = n ; i = 2) S = 1 (FLOAT) I; return (s);} float dcall (fp, n) float (fp) (); int N; {float s; s = (fp) (n); return (s);} [program 77] Title: Fill in the exploitation (pointing to the pointer to the pointer) 1. Program analysis: 2. Program source code: main () {char s [] = {Man, Woman, Girl, Boy, Sister} CHAR Q; INT K; for (k = 0; k5; k ) {; what statements Printf (% Sn, Q) here are filled in;}} [program 78] Title: Find the oldest person, and output. Please find out what problems in the program. 1. Program analysis: 2. Source code: #define n 4 # include stdio.hstatic struct man {char name [20]; int Age;} Person [N] = {Li, 18, WANG, 19, ZHANG, 20 , Sun, 22}; main () {struct man q, p; int i, m = 0; p = person; for (i = 0; in; i ) {IF (MP-AGE) q = p ; m = Q-Age;} Printf (% s,% d, (q) .name, (q) .age);} [program 79] topic: string sort.