Classic C procedure 100 cases

xiaoxiao2021-03-06  116

[Procedure 1] Title: Classical question: There is a pair of rabbits, from the third month of birth, a pair of rabbits every month, the bunny grows to the third month after each month, if the rabbit Don't die, 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, each line four * / f1 = f1 f2; / * added to the third month * / f2 = f1 f2; / * added to the third two months to assign a value to the third Month * /}} ============================================== ================= 【Program 2】 Title: How many of the numbers between 101-200, and output all the numbers. 1. Program analysis: Method for judging the number of prime: Use a number to remove 2 to SQRT (this), if it can be tightened, indicate that this is not a prime number, but it is the number of prime numbers. 2. Program source code: #include "math.h" main () {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);} = ============================================================================================================================================================================================================= =========== 程序 程序 3] Title: Print all "Number of daffodils", the so-called "number of daffodils" refers to a three-digit number, and its digital cubes and is 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; n <1000; n ) {i = N / 100 ; / * Decompose hundreds of * / j = n / 10% 10; / * Decompose ten * / k = n% 10; / * Decompose a bit * / if (i * 100 j * 10 k == i * i * i j * j * j k * k * k) {printf ("% - 5d", n);}}}} printf ("/ n");} ======= ============================================================================================================================================================================================================= ===== [Program 4] Title: A positive integer is decomposed. For example: input 90, print 90 = 2 * 3 * 3 * 5. 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 n <> k, but N can be removed by K, the value of K should be printed, and the use of N 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 divid Yinshu * / main () {Int n, i; printf ("/ nplease input a number: / n"); scanf ("% d", & n); printf "% d =", N); for (i = 2; i <= n; i ) {while (n! = i) {if (n% i == 0) {printf ("% d *", i ); N = n / i;} else break;}} printf ("% d", n);} ========================== ============================================== 【Program 5】 Title: Nested the conditional operator To do this: Academic performance> = 90 students use a to represent, 60-89 points, b, 60, clicker, and c. 1. Program analysis: (a> b)? A: b This is the basic example of the conditional operator. 2. Program source code: main () {int score; char grade; printf ("please input a score / n"); scanf ("% d", & score); grade = score> = 90? 'A' :( Score> = 60? 'b': 'c'); Printf ("% D Belongs TO% C", score, grade);} =================== =================================================== 【程序 6] Title: Enter Two positive integers m and n, seeking their maximum number of conventions and the least common multiple. 1. Program analysis: Using the rolling method.

2. Program source code: main () {Int A, B, Num1, Num2, Temp; Printf ("please input two number: / n"); scanf ("% D,% D", & Num1, & num2); if (Num1 = Num2; Num2 = Num2; Num2 = Temp;} a = Num1; b = Num2; while (b! = 0) / * utilization Rolling method until B is 0 * / {TEMP = a% B A = B; B = Temp;} Printf ("Gongyueshu:% D / N", A); Printf ("Gongbeishu:% D / N", Num1 * Num2 / a);} ======= ============================================================================================================================================================================================================= ===== [Program 7] Title: Enter a line of characters, statistics of the number of English letters, spaces, numbers, and other characters, respectively.

1. Program analysis: Use the While statement, the condition is not the characters entered by the input. 2. Source code: #include "stdio.h" main () {char C; int letters = 0, Space = 0, DIGIT = 0, OTHERS = 0; Printf ("Please Input Some Characters / N); 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 all: char =% d Space =% D DIGIT =% D =% d / n", letters, space, digit, tahers;} ============ ============================================================================================================================================================================================================= [Program 8] Title: See the value of S = A AA AAA AAAA AA ... A, 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 n / n"); scanf ("% D,% D ", & A, & n); Printf (" A =% D, N =% D / N ", A, N); while (count <= n) {TN = Tn a; SN = Sn Tn; A = A * 10; count;} Printf ("A AA ... =% ld / n", SN);} ===================== ================================================================================================================================================================================= 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. Source code: main () {static int K [10]; int 1, j, n, s; for (j = 2; J < 1000; J ) {n = -1; s = j; for (i = 1; i {IF ((j% i) == 0) {n ; s = Si; k [n] = i;}}} (s == 0) {Printf ("% d is a wanshu", j); for (i = 0; I printf ("% d,", k); Printf ("% d / n", k [n ]);}}} ======================================================================================================================================================================= ================== 【Procedure 10】 Title: One goal from 100 meters highly free, each time the end of the anti-jump back to the original height; then fall, ask for it When the 10th floor landed, how many meters? The 10th rebound increased? 1. Procedure analysis: See the comment below 2. Source code: main () {float Sn = 100.0, hn = SN / 2; INT N ; for (n = 2; n <= 10; n ) {SN = Sn 2 * HN; / * Number of rice in the first place * / hn = hn / 2; / * Native jump Highness * /} Printf ("THE TOTAL OF ROAD IS% F / N", SN); Printf ("Tenth IS% F meter / n", HN);} [Program 11] Title: There are 1, 2, 3 , 4 numbers, how many three digits that are different and no repeated numbers? 1. Procedure analysis: Can be filled in 100, ten, bit numbers are 1, 2, 3 4. Remove the arrangement of the conditions after all the arrangements.

2. Program source code: main () {INT I, J, K; Printf ("/ n"); for (i = 1; i <5; i ) / * The following is a triple loop * / for (j = 1 J <5; J ) for (k = 1; k <5; k ) {if (i! = k && i! = j! = k) / * Make sure I, J, K three mutually different * / printf "% D,% D,% D / N", I, j, k);}} ============================ ========================================================================================================================================================================================================================】 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, bons4, bons6, bons10, bons; scanf ("% ld", & i); bonus1 = 100000 * 0.1; bonus2 = Bonus1 100000 * 0.75 Bonus4 = BONUS2 200000 * 0.5; Bonus6 = Bonus4 200000 * 0.3; Bonus10 = BONUS6 400000 * 0.15; IF (i <= 100000) Bonus = i * 0.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);}

============================================================================================================================================================================================================= ============ 程序 程序 13] Title: an integer, it is 100 after 100 is a complete square, plus 168 is a complete square number, how much is it? 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.h" main () {long Int i, x, y, z; for (i = 1; i <100000; i ) {x = SQRT (i 100); / * x is the result of adding 100 after the beginning * / y = SQRT (i 268); / * y is the result of the 1 after 168 after the 1st 1 * / if (x * x = = i 100 && y * y == i 268) / * If a number of square roots of a number is equal to this, this indicates that this is completely square * / printf ("/ n% ld / n", i);} } ==================================================== ============= 【Program 14】 Title: 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, day / n"); scanf ("% D,% D,% D", & Year, & Month, & Day); Switch (MONTH) / * First calculate the total number of days in 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 = 273; Break; Case 11: Sum = 304; Break; Case 12: Sum = 334; Break; Default: Printf ("Data Error"); Break;} Sum = SUM Day; / * plus a certain day * / if (Year% 400 == 0 || (Year% 4 == 0 && year% 100! = 0)) / * Judgment is a leap year * / leap = 1; ELSE Leap = 0; if (Leap == 1 && Month> 2) / * If it is a leap year and greater than 2, the total number of days should add a day * / sum ; Printf ("IT is the% DTH day.", sum);} == ============================================================================================================================================================================================================= ========== 【Program 15】 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 to the X, first compare X and Y, if X> Y swaps X and Y, then use x and z, if x > z Exchange X with the value of Z, which makes X minimizes.

2. Program source code: main () {INT X, Y, Z, T; Scanf ("% D% D% D", & x, & y, & z); if (x> y) {t = x; x = Y; y = t;} / * swap x, y value * / if (x> z) {t = z; z = x; x = T;} / * exchange x, z value * / if (Y > z) {t = y; y = z; z = t;} / * exchange z, y value * / printf ("Small TO BIG:% D% D% D / N", x, y, z) } ================================================== ============== 【Program 16】 Title: Output the pattern of letter C with *. 1. Program analysis: You can use the '*' number to write the letter C to the paper, and then the branch is output. 2. Program source code: #include "stdio.h" Main () {printf ("Hello C-World! / N"); Printf ("**** / n"); printf ("* / n") PRINTF ("* / n"); Printf ("**** / n");} =========================== ============================================ 【Program 17】 Title: Output special patterns, please in the C environment Run, take a look, Very Beautiful! 1. Program analysis: 256 characters. Different characters, graphics are different.

2. Program source code: #include "stdio.h" main () {char A = 176, b = 219; Printf ("% 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 / N", A , A, B, A, A); Printf ("% C% C% C% C / N), A, B, A, B, A); Printf ("% C% C% C%) C / N ", B, A, A, A, B);} ================================== ============================= 【Program 18】 Topic: Output 9 * 9 口. 1. Program analysis: Branch and column considerations, a total of 9 rows, I control line, J control column. 2. Program source code: #include "stdio.h" Main () {INT i, J, Result; Printf ("/ n"); 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 bits * /} printf ("/ n"); / * After each line, the wrap * /}} ================================== ============================= 【Program 19】 Title: Requires Output Chess Chessboard. 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.h" main () {INT i, j; for (i = 0; i <8; i ) {for (j = 0; j <8; j ) IF ((( i j)% 2 == 0) Printf ("% C% C", 219, 219); Else Printf (""); Printf ("/ n");}} =========== ============================================================================================================================================================================================================= = [Program 20] 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. Program source code: #include "stdio.h" main () {INT i, j; printf ("/ 1/1 / n"); / * Output two smile * / for (i = 1; i < 11; i ) {for (j = 1; j <= i; j ) Printf ("% C% C", 219, 219); Printf ("/ n");}} [program 21] Title: Monkey eat peach problem : The monkey took a few peaches on the first day, and immediately took half, not addict, and also ate a few days in the morning and eat half of the peach, and ate one more. 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 (day> 0) {x1 = (x2 1) * 2; / * The number of peaches on the first day It is the 2nd day of the peach number plus 1 after adding 1 * / x2 = x1; day--;} Printf ("Total IS% D / N", 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. Program source code: main () {char i, j, k; / * i is a opponent, J is the opponent of B, k is the opponent of C * / for (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 -% C / TB -% C / TC-- % C / N ", I, J, K);}}}} ================================= ============================= 【Program 23】 Title: Print the following pattern (diamond)

************************************* 1. Program analysis: First divide the graphic into two parts, the first four lines, one rule, then three A routine, using a dual for loop, 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 <= 2 * i; k ) Printf ("*"); printf ("/ n");} for (i = 0; i <= 2; i ) {for (J = 0; j <= i; j ) Printf (""); for (k = 0; k <= 4-2 * i; k ) printf ("*"); printf ("/ n");}} ============================================================================================================================================================================================================= ============ 【Program 24】 Topic: One Piece Sequence: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13 ... 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 A / B; t = a; a = a b; b = t; / * This part is the key to the program, please reader guess T role * /} printf ("Sum IS% 9.6F / N", S );} =============================================== =============== 【程序 2 25】 Title: See Qi 1 2! 3! ... 20! And 1. Program Analysis: This procedure is just the accumulation Towerful.

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! =% E / N ", S);} ============================ ================================== 【程序 2 26】 Title: Use the recursive method to find 5 !. 1. Program analysis: recursive formula: fn = fn_1 * 4! 2. Source code: #include "stdio.h" main () {INT i; int fact (); for (i = 0; i <5; i PRINTF ("/ 40:% D! =% D / N", I, FACT (I));} INT FACT (J) INT J; {INT SUM; IF (J == 0) SUM = 1; ELSE SUM = J * FACT (J-1); return sum;} ===================================== =========================== 【程序 27] Title: Use the recursive function call mode, the 5 characters entered in the opposite order print it out.

1. Program analysis: 2. Source code: #include "stdio.h" main () {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 ("/ n / 0:"); PUTCHAR (NEXT);} Else {Next = getchar (); PALIN (N-1); Putchar (next);}} ============================= ================================== 【程序 2 28】 Title: There are 5 people sitting together, ask the fifth How old is your personal? 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));} ===================================== ========================== 【程序 2 29】 Title: give a positive intent of 5 digits, require: First, ask it is Several digits, second, reverse sequence print out numbers.

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 = x / 10000; / * Decompose 10,000 * / b = x% 10000/1000; / * Decompose thousands * / c = x % 1000/100; / * Decompose hundreds of * / d = x% 100/10; / * Decompose ten * / e = x% 10; / * Decompose a bit * / if (a! = 0) Printf ("there is" LD / N ", E, D, C, B, A); ELSE IF (B! = 0) Printf (" There Are 4,% LD% LD% ld% ld / n ", e, d, c, b); ELSE IF (C! = 0) Printf (" there is are 3,% ld% ld% ld / n ", e, d, c); Else if (D! = 0) Printf ("there is 2,% ld% ld / n", e, d); ELSE IF (e! = 0) Printf ("there are 1,% ld / n", e );} =============================================== =============== 【Program 30】 Title: A 5 digit, it is determined that it is not 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 = x / 10000; qian = x% 10000 / 1000; shi = x% 100/10; ge = x% 10; if (ge == wan && shi == qian) / * bit is equal to 10,000 and ten equal to thousands * / printf ("this number is a huiwen / N "); Else Printf (" this number is not a huiwen / n ");} [Program 31] Topic: Please enter the first letter of the day of the week to judge the day, if the first letter is the same, The second letter will continue to be judged. 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 void main () {char letter; printf ("please infut the first letter of someday / n"); while ((Letter = getch ())! = 'Y' ) / * End * / {switch ("" ":" "); if (" please = getch ()) == 'A' is over when the letter is Y. ) PRINTF ("SATURDAY / N"); Else IF ((Letter = getCH ()) == 'u') Printf ("sunday / n"); Else Printf ("Data Error / N"); Break; Case ' F ': Printf ("friday / n"); Break; Case' M ': Printf ("Monday / N"); Break; Case' T ': Printf ("please input letter letter / n"); if (( Letter = getCH ()) == 'u') Printf ("Tuesday / N"); Else IF ((Letter = getCH ()) == 'h') Printf ("thursday / n"); Else Printf (" Data error / n "); Break; Case 'W': Printf (" Wednesday / N "); Break; Default: Printf (" Data Error / N ");}}} ========== ============================================================================================================================================================================================================= == [Program 32] Title: Press any key to change color, do you want to try! Please hurry up! 1. Program analysis: 2. Source code: #include void main (void) { Int Color; for (color = 0; Color <8; color ) {textbackgr Ound (color); / * Set text background color * / cprintf ("this is color% d / r / n", color); CPrintf ("press any key to continue / r / n"); getCh (); / * Enter characters can't see * /}} =============

============================================================================================================================================================================================================= [Program 33] Title: Learning Gotoxy () and CLRSCR () Functions 1. Program Analysis: 2. Source Code: #include void main (void) {ClrsCr (); / * Clear screen function * / Textbackground (2); gotoxy (1, 5); / * Positioning function * / cprintf ("Output At Row 5 Column 1 / N); Textbackground (3); Gotoxy (20, 10); CPrintf (" Output At Row 10 COLUMN 20 / N ");} ========================================== ====================== 程序 程序 34] Title: Exercise function call 1. Program analysis: 2. Source code: #include void Hello_World (void) {Printf ("Hello, World! / N");} void three_hellos (void) {int counter; for (counter = 1; counter <= 3; counter ) hello_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 void main (void) {int color; for (color = 1; color <16; color ) {textcolor; / * Set text color * / cprintf ("this is color% d / r / n ", color);} TextColor (128 15); CPRINTF ("

This is blinking / r / n ");} ========================================= ======================= 【Program 36】 Title: Queuity within 100 Prouses 1. Program Analysis: 2. Source Code: #include #include "math.h" #define n 101main () {INT I, J, LINE, A [N]; for (i = 2; i

2. Program source code: #define n 10main () {INT i, J, min, tem, a [n]; / * input data * / printf ("please input ten num: / n"); for (i = 0; i a [j]) min = j; TEM = a; a = a [min]; a [min] = tem;} / * Output Data * / printf ("after sorted / n"); for (i = 0; i

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 IS: / N"); for (i = 0; i <10; i ) Printf ("% 5d", a); Printf ("/ n"); Printf ("INSERT A New Number:" ); scanf ("% d", & number); end = a [9]; if (number> end) a [10] = number; else {for (i = 0; i <10; i ) {IF (A > Number) {TEMP1 = a; a = number; for (j = i 1; j <11; j ) {temp2 = a [j]; a [j] = temp1; temp1 = temp2;} Break;}} } for (i = 0; i <11; i ) Printf ("% 6d", a);} ========================================================================================================== =================================================================================== 程序 程序 逆 输. 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 array: / n"); for I = 0; i

1. Program analysis: 2. Source code: #include "stdio.h" main () {INT I, NUM; NUM = 2; for (i = 0; i <3; i ) {printf ("/ 40: THE NUM EQUAL% D / N ", NUM); Num ; {Static Int Num = 1; Printf (" / 40: THE INTERNAL BLOCK NUM EQUAL% D / N ", NUM); NUM ;}}} ==== ============================================================================================================================================================================================================= ======== [Program 44] Title: Learn to use External usage. 1. Program analysis: 2. Program source code: #include "stdio.h" int A, b, c; void add () {Int a; a = 3; c = a b;} void main () {A = B = 4; add (); Printf ("The value of c is equals%% d / n", c);} ===================== ================================================= 【Procedure 45】 Title: Learn to use Register Define 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% D / n ", TMP);} ========================================== ==================== 【Program 46】 Title: Macro #define command exercise (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 "{Printf ("/40:please input number ===>"); scanf ("% d", & num); printf ("/ 40: the square for this number IS% D / N ", SQ (NUM)); if (num> = 50) again = true; else again = false;}} ===================== ================================================= 【Program 47】 Title: 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 orders are allowed, Plus "/" * / int T; t = a; a = b; b = t;} void main (void) {int x = 10; int y = 20; printf ("x =% D; Y =% d / n ", x, y); Exchange (x, y); Printf (" x =% D; y =% D / N ", x, y);} ======== ==========

==================================================== 【Program 48】 Title: Macro #define command exercises (3) 1. Program analysis: 2. Source code: #define lag> #define sma <#define EQ == # include "stdio.h" void main () {int i = 10; int = J = 20; IF (i LAG J) Printf ("/ 40:% d Larger Than% D / N", I, J); ELSE IF (I EQ J) Printf ("/ 40:% D Equal TO% D / N ", I, J); ELSE IF (I SMA J) Printf (" / 40:% D Smaller 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) (x> y)? X: y # define minimum (x, y) (x> y) )? Y: xvoid main () {INT A = 10, b = 20; #ifdef maxprintf ("/ 40: the larder one IS% D / N", Maximum (a, b)); # elseprintf ("/ 40 : The Lower One Id% D / N ", Minimum (A, B)); # Endif # IFNDEF MinPrintf (" / 40: The Lower One IS% D / N ", Minimum (A, B)); # elseprintf ( "/ 40: The larger one IS% D / N", Maximum (a, b)); # Endif # undef max # ifdef maxprintf ("/ 40: the lar one is% d / n", Maximum (A, B ))); # elseprintf ("/ 40: The Lower One IS% D / N", Minimum (a, b)); # Endif # define min # ifndef minprintf ("/ 40: The Lower One IS% D / N" , Minimum (a, b)); # elseprintf ("/ 40: the larder one IS% D / N", Maximum (a, b)); # endif} ============= ==============================================================================】 Program 50] Topic: #include application practice 1. Program analysis: 2. Source code: Test.h files as follows: #define lag> #define sma <#define eq == # include "test.h" / * one New file 50.c, containing test.h * / # include "stdio.h" void main () {int i = 10; int J = 20; if (i lag j) Printf ("/ 40:% d Larger Than % D / N ", I, J); ELSE IF (i EQ J) Printf (" / 40:% D Equal TO% D / N ", I, J); ELSE IF (i SMA J) Printf ("/ 40:% D Smaller THAN% D / N", I, J); ElsePrintf ("/ 40: no such value./n");} [Program 51] Title: Learning and use versus& .

1. Program analysis: 0 & 0 = 0; 0 & 1 = 0; 1 & 0 = 0; 1 & 1 = 12. Source code: #include "stdio.h" main () {Int A, b; a = 077; b = a & 3; printf ("/ 40: THE A & B (DECIMAL) IS% D / N", B); B & = 7; Printf ("/ 40: The A & B (DECIMAL) IS% D / N", B);} ============================================================================================================================================================================================================= ============ 【Program 52】 Topic: Learn to use bit or |. 1. Program analysis: 0 | 0 = 0; 0 | 1 = 1; 1 | 0 = 1; 1 | 1 = 1 2. Source code: #include "stdio.h" main () {Int A, b; A = 077; b = a | 3; Printf ("/ 40: THE A & B (DECIMAL) IS% D / N", B); B | = 7; Printf ("/ 40: The A & B (Decimal IS% D / N ", B);} ======================================= ====================================================================================================================================================================================================================】

1. Program analysis: 0 ^ 0 = 0; 0 ^ 1 = 1; 1 ^ 0 = 1; 1 ^ 1 = 02. Source code: #include "stdio.h" main () {Int A, b; A = 077; b = a ^ 3; Printf ("/ 40: the a & b); b); b); b ^ = 7; Printf (" / 40: The a & b (Decimal) IS% D / N ", B);} ======================================= ======================= 【Program 54】 Topic: Take an integer A from 4 to 7 bits 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. Use ~ (~ 0 << 4) (3) to carry out both the above. 2. Program source code: main () {UNSIGNED A, B, C, D; SCANF ("% O", & a); b = a >> 4; c = ~ (~ 0 << 4); d = B & C PRINTF ("% O / N% O / N", A, D);} =============================== ======================================== 程序 程序 55】 Title: Learn to use the bitwise to reflect ~.

1. Program analysis: ~ 0 = 1; ~ 1 = 0; 2. Source code: #include "stdio.h" main () {Int A, b; a = 234; b = ~ a; printf ("/ 40: THE A'S 1 Complement (Decimal) IX% D / N ", B); A = ~ a; Printf (" / 40: The a's 1 Complement (HexideCIMAL) IS% X / N ", A);} == ============================================================================================================================================================================================================= ========== [Program 56] Topic: Draw, learn Circle painted circular. 1. Program analysis: 2. Source code: / * Circle * / # include "graphics.h" main () {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;}} ============================================ =================== 程序 程序 57] Topic: Draw, learn line painting line.

1. Program analysis: 2. Program source code: #include "graphics.h" main () {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】 Topic: 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.h" main () {Int x0, y0, y1, x1, driver, mod, 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】 Title: Draw, integrated example.

1. Program analysis: 2. Source code: # define pai 3.1415926 # Define B 0.809 # include "graphics.h" #include "math.h" main () {INT i, J, K, X0, Y0, X, Y, 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; I <16; i ) {a = (2 * pai / 16) * i; x = ceil (X0 48 * COS (A)); Y = CEIL (Y0 48 * SIN (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 (); set1fillstyle (Hatch_fill, Yellow); floodfill (202, 100, white); getCh (); for (k = 0; k <= 500; k ) {setColor (3); for (i = 0; i <= 16; i ) {a = (2 * PAI / 16) * i (2 * PAI / 180) * K; x = CEIL (X0 48 * COS (A)); y = CEIL (Y0 48 SIN (a) * b); setColor (2); line (x0, y0, x, y);} for (j = 1; j <= 50; j ) = (2 * pai / 16) * i (2 * pai / 180) * k-1; x = CEIL (x0 48 * cos (a)); y = CEIL (Y0 48 * sin (a) * b); line (x0, y0, x, y);}}}}}} ==== ============================================================================================================================================================================================================= ======== [Program 60] Title: Draw, integrated 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; 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 <= left || x1> = Right) DX1 = -dx1; if (Y1 <= TOP || Y1> = BOTTOM) DY1 = -DY1; IF (x2 < = LEFT || X2> = Right) DX2 = -dx2; if (Y2 <= TOP || Y2> = BOTTOM) DY2 = -DY2; if ( Count> Lines) {setColor (color); color = (Color > = MaxColor)? 0: color;}} closegraph ();} program 61】 Title: Print Yang Hui triangle (requirement 10 lines as shown below) 1. Program analysis: 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; I <10; i ) {a [0] = 1; a = 1;} for (i = 2; i <10; i ) for (j = 1; j

1. Program analysis: 2. Program source code: #include "stdio.h" #include "graphics.h" Main () {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 ) PUTPEL (i, j, 1); for (j = 50; J <= 230; j = 20) for (i = 50; i <= 230; i ) PUTPIEL (i, j, 1);} ================== ==================================================== 【Program 63】 Title: Painting Ellipse Ellipse 1. Program Analysis: 2. Source Code: #include "stdio.h" #include "graphics.h" #include "conoe.h" main () {int x = 360, y = 160, driver = VGA, MODE = VGAHI; INT NUM = 20, I; INT TOP, BOTTOM; INITGRAPH (& Driver, & Mode, "); TOP = Y-30; bottom = Y-30; for (i = 0; i

1. Program analysis: 2. Source code: #include "stdio.h" #include "graphics.h" #include "conoe.h" main () {int DRIVER = VGA, MODE = VGAHI; INT I, NUM = 15, TOP = 50; INT LEFT = 20, Right = 50; INITGRAPH (& Driver, & Mode, ""); for (i = 0; i

1. Program analysis: 2. Source code: #include "graphics.h" #include "math.h" #include "dos.h" #includ "conio.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 (& VP); H = VP.BOTTOM - VP.TOP; W = vp.right - vp.Left; xcenter = W / 2; / * determine the center of circle * / ycenter = h / 2; radius = (h - 30) / (aspectratio * 2); Step = 360 / maxpts; / * Determine # of increments * / ang = 0; / * begin at zero degRees * / for (i = 0; i

============================== 【Program 66】 Title: Input 3 numbers A, B, C, output according to the size order . Program analysis: Using the pointer method. 2. Program source code: / * Pointer * / main () {INT N1, N2, N3; INT * POINTER1, * POINTER2, * POINTER3; Printf ("Please Input 3 Number: N1, N2, N3:"); scanf ("% D,% D,% D", & n1, & n2, & n3); Pointer1 = & n1; Pointer2 = & n2; Pointer3 = & n3; if (n1> n2) SWAP (Pointer1, Pointer2); if (n1> n3) SWAP (Pointer1, Pointer3); IF (N2> N3) Swap (Pointer2, Pointer3); Printf ("The sorted number are:% D,% D,% D / N", 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; I <9; i ) scanf ("% D,", & number); 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; p * max) max = p; Else if (* p <* min) 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; p Arr AY; P -) * p = * (P-1); * array = array_end; m -; if (m> 0) Move (array, n, m);} ========= =========

==================================================== 【Program 69】 Title: Have n personal encloses 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. Program source code: #define nmax 50mAin () {INT i, k, m, n, num [nmax], * p; printf ("please input the total of numbers:"); scanf "% d", & n); p = Num; for (i = 0; i

1. Program analysis: 2. Source code: #define n 5struct student {char Num [6]; char name [8]; int score [4];} stu [n]; input (stu) Struct Stu [] ; {INT I, J; For (i = 0; i

1. Program analysis: 2. Program source code: / * Creat a list * / # include "stdlib.h" #include "stdio.h" struct list {int data; structure; struct list * next;}; typef struct List Node; Typedef node * 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-> next;} Ptr = head; while (ptr! = null) {printf ("the value is ==>% d / n", Ptr -> data); PTR = Ptr-> Next;}} ==================================== ========================== 【Program 73】 Title: Reverse output a linked list.

1. Program analysis: 2. Source code: / * Reverse output a list * / # include "stdlib.h" #include "stdio.h" struct list * next;}; typedef struct List Node TYPEDEF NODE * LINK; Void Main () {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 = (link) malloc (SIDEOF (Node); ptr = head;} ​​ptr = ptr-> next; while (ptr! = null) {printf ("The value is ==>% d / n", Ptr -> data); PTR = Ptr-> Next;}} ==================================== ========================== 【Program 74】 Title: Connect two linked lists.

1. Program analysis: 2. Source code: #include "stdlib.h" #include "stdio.h" struct list {int data; struct list * next;}; type; typef node * link; link delete_node (LINK POINTER, LINK TMP) {IF (TMP == NULL) / * Delete first node * / return Pointer-> Next; else {if (tmp-> next-> next == null) / * delete last node * / TMP-> Next = NULL; Else / * delete the} = tmp-> next-> next; return pointer;}}} void selection_sort (link pointer, int num) {link TMP, BTMP; int I, min; for (i = 0; I data; btmp = null; while (tmp-> next) {if (min> tmp-> next-> Data) {min = tmp-> next-> data; btmp = tmp;} TMP = TMP-> Next;} Printf ("/ 40:% d / n", 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; i next = null; tmp2-> data = array; tmp1-> next = TMP2; TMP1 = TMP1-> Next;} Return Pointer;} link control (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, count a simple topic.

1. Program analysis: 2. Source code: main () {INT i, n; for (i = 1; i <5; 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);}} ===================================== ============================ 程序 程序 76] Topic: Write a function, enter N is an even number, the call function is 1/2 1/4 ... 1 / n, when entering N is odd, call function 1/1 1/3 ... 1 / n (utilization pointer function) 1. Program analysis: 2. Program Source code: main () # include "stdio.h" main () {float peven (), podd (), dcall (); float sum; int n; while (1) {scanf ("% d", & n) ; If (n> 1) 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 1; 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 exploration exercise (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; k <5; K ) {; / * What statements * / printf ("% s / n", * q) here;}} ======================= ======================================= 【程序 7 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.h" static struct man {char name [20]; int Age;} Person [N] = {"Li", 18, "Wang ", 19," zhang "," sun ", 22}; main () {struct man * q, * p; int i, m = 0; P = Person; for (i = 0; i agn) q = p ; m = Q-> Age;} printf ("% s,% d", (* q) .Name, (* Q) .age);} ============================================================================================================================================================================================================= ============ 【Program 79】 Title: String sort.

1. Program analysis: 2. Source code: main () {char * str1 [20], * str2 [20], * STR3 [20]; char swap (); Printf ("please input throughs / n") Scanf ("% S", STR1); Scanf ("% s", str2); scanf ("% s", str3); IF (strCMP (STR1, STR2)> 0) SWAP (STR1, STR2); IF (strcmp (str3, str3)> 0) SWAP (STR1, STR3); IF (strCMP (STR2, STR3)> 0) SWAP (STR2, STR3); Printf ("after being sorted / n"); printf ("% S / N% S / N% S / N ", STR1, STR2, STR3);} CHAR SWAP (P1, P2) CHAR * P1, * P2; {Char * P [20]; STRCPY (P, P1); STRCPY (P1, P2); STRCPY (P2, P);} ===================================== ============================ 程序 程序 80] Title: There is a pile of peaches on the beach, five monkeys. The first monkey divided this pile of peach credentials into five, more than one, this monkey threw more into the sea and took a copy. The second monkey divides the remaining peaches averaged five, and one more, it also threw more one into the sea, took a one, third, fourth, fifth monkeys are doing this , Ask how many peaches in the beach are the original? 1. Program analysis: 2. Source code: main () {INT I, M, J, K, Count; for (i = 4; i <10000; i = 4) {count = 0; m = i; for (k = 0; k <5; k ) {j = I / 4 * 5 1; i = j; if (j% 4 == 0) count ; else break;} i = m; if (count == 4) {Printf ("% d / n", count); break;}}} [program 81] Title: 809 * ?? = 800 * ?? 9 * ?? 1 where two digits represent The result of 8 * ?? is two digits, and the result of 9 * ?? is 3 digits. Request for the two digits of the representative, and the result of 809 * ??.

1. Program analysis: 2. Source code: OUTPUT (long b, long i) {printf ("/ n% ld /% ld = 809 *% ld % ld", B, I, I, b% i); } main () {long Int A, B, I; A = 809; for (i = 10; i <100; i ) {b = i * a 1; if (b> = 1000 && b <= 10000 && 8 * i < 100 && 9 * i> = 100) Output (b, i);}} ================================== ============================ 【Program 82】 Title: Octa conversion to decimal 1. Program analysis: 2. Program source code: main () {char * p, s [6]; int N; p = S; Gets (p); n = 0; while (* (p)! = '/ 0') {n = n * 8 * P -'0 '; p ;} Printf ("% d", n);} =============================== ======================================= 【Program 83】 Title: Seeking the odd number of odd numbers that can be composed of 0-7. 1. Program analysis: 2. Source code: main () {long sum = 4, s = 4; int J; for (j = 2; j <= 8; j ) / * j is place of number * / { Printf ("/ n% ld", sum); if (j <= 2) s * = 7; else * = 8; SUM = S;} Printf ("/ nsum =% ld", sum);} == ============================================================================================================================================================================================================= ========== [Program 84] Title: A number of even numbers can be represented as the sum of two prime numbers.

1. Program analysis: 2. Source code: #include "stdio.h" #include "math.h" main () {Int A, B, C, D; scanf ("% d", & a); for B = 3; B <= a / 2; b = 2) {for (c = 2; c <= SQRT (B); C ) IF (b% c == 0) Break; if (c> sqrt (B )) D = ab; elsebreak; for (c = 2; c <= SQRT (D); C ) IF (D% c == 0) Break; if (c> SQRT (D)) Printf ("% D = % D % D / N ", A, B, D);}} =================================== ============================= 【Program 85】 Title: Judgment a number of numbers can be taken 9 整 1. Program analysis: 2 . Source code: main () {long int m9 = 9, sum = 9; int zi, n1 = 1, c9 = 1; scanf ("% d", & zi); while (n1! = 0) {IF ! (sum% zi)) N1 = 0; ELSE {m9 = m9 * 10; sum = SUM M9; C9 ;}} printf ("% ld, can be divided by% D /" 9 / ", SUM, C9);} ============================================== ================ 【Program 86】 Title: Two string connections 1. Program analysis: 2. Source code: #include "stdio.h" main () { Char a [] = "acegikm"; char b [] = "bdfhjlnpq"; char C [80], * p; int i = 0, j = 0, k = 0; While (a! = '/ 0' && B [j]! = '/ 0') {IF (a {C [k] = a; i ;} elsec [k] = b [j ]; k ;} C [k] = '/ 0'; if ( A == '/ 0') P = B J; Elsep = A I; STRCAT (C, P); PUTS (C);

} ==================================================== ============= 程序 程序 8题: Answer results (structural variable delivery) 1. Program analysis: 2. Program source code: #include "stdio.h" struct student {Int x CHAR C;} a; main () {ax = 3; ac = 'a'; f (a); printf ("% D,% C", AX, AC);} f (struct student b) {BX = 20; bc = 'y';} ======================================== ====================== 【Program 88】 Topic: Read 7 (1-50) integer values, each read a value, program print The number of this value is displayed. 1. Program analysis: 2. Source code: main () {INT i, a, n = 1; while (n <= 7) {DO {scanf ("% d", & a);} while (a <1 || a> 50); for (i = 1; i <= a; i ) printf ("*"); printf ("/ n"); n ;} getCH ();} ======= ============================================================================================================================================================================================================= ===== [Program 89] Topic: A company uses public telephone delivery data, data is an integer, encrypted in the delivery process, encrypted rules are as follows: Each number plus 5, then use and Instead of this number, the first bit and the fourth interchange are exchanged, and the second bit and the third one are exchanged.

1. Program analysis: 2. Program source code: main () {Int A, i, aa [4], t; scanf ("% d", & a); AA [0] = a% 10; AA [1] = a% 100/10; AA [2] = a% 1000/100; AA [3] = A / 1000; for (i = 0; i <= 3; i ) {aa = 5; AA% = 10; } for (i = 0; i <= 3/2; i ) {t = aa; aa = aa [3-i]; AA [3-i] = t;} for (i = 3; i> = 0 i -) Printf ("% d", aa);} ==================================== ===================================================================================================== 【Program 90】

1. Program analysis: 2. Source code: #include "stdio.h" #define m 5main () {int a [m] = {1, 2, 3, 4, 5}; Int i, j, t; i = 0; j = m-1; while (i {t = * (A i); * (A i) = * (A J); * (a j) = t; i ; J- -;} for (i = 0; i printf ("% d", * (a i));} [program 91] topic: Time function example 11. Program analysis: 2. Sample source code: #include "stdio .h "#include" time.h "void main () {time_t lt; / * define a longint time varible * / lt = time (null); / * system time and date * / printf (ctime); / * English format output * / printf (asctime (localtime (<))))); / * TRANFER TOTM * / Printf (asctime (gmtime (gmtime))); / * TRANFER TO GREENWICH TIME * /} ===== ============================================================================================================================================================================================================= ======= Title: Time function example 21. Program analysis: 2. Source code: / * Calculate Time * / # include "time.h" #include "stdio.h" main () {TIME_T START, END; INT i; start = TIME (NULL); for (i = 0; i <3000; i ) {printf ("/ 1/1/1/1/1/1/1/1/1 / 1 / n ");} end = time (null); Printf (" / 1: THE DIFFERENT IS% 6.3F / N ", DIFFTIME (END, START));} ========== ============================================================================================================================================================================================================= == [Program 93] Title: Time Function Example 31. Program Analysis: 2. Source Code: / * Calculate Time * / # include "Time.h" #include "stdio.h" Main () {Clock_t Start, End ; Int i; Doubl e var;

START = clock (); for (i = 0; i <10000; i ) {printf ("/ 1/1/1/1/1/1/1/1/1 / n");} END = Clock (); Printf ("/ 1: THE DIFFERENT IS% 6.3F / N", (Double) (End-start);} =================== =========================================================================================== 【Program 94】 Title: Time Function Example 4, a guessing game, judge that a person reacts slowly.

(Moderator first school) 1. Procedure analysis: 2. Source code: #include "time.h" #include "stdlib.h" #include "stdio.h" main () {char C; clock_t start, End; Time_t A, B; Double Var; INT I, GUESS; SRAND (Time (NULL)); Printf ("Do You Want To Play IT. ('Y' or 'N') / N"); loop: while ((c = getChar ()) == 'y') {i = rand ()% 100; Printf ("/ NPLEase: / N"); start = clock (); a = time (null) Scanf ("% D", & guess; while (guess! = i) {if (Guess> i) {printf ("please input a little smaller./n" ";scanf("%d" ,und); } else {printf ("please input a little bigger./n" ";scanf ("%d" ,und );}}} }b=time(null );printf("/1: IT TOOK YOU% 6.3f Seconds / N ", VAR = (Double) (end-start) /18.2); Printf (" / 1: IT TOOK You% 6.3f Seconds / N / N ", DiffTime (B, A)); IF (var <15) Printf ("/ 1/1 you are very very clever! / 1/1 / n / n"); Else IF (var <25) Printf ("/ 1/1 you are normal! / 1 / 1 / N / N "); elseprintf (" / 1/1 you are stupid! / 1/1 / n / n "); Printf (" / 1/1 congraDulation / 1/1 / n / n "); Printf ("THE NUMBER You Guess IS% D", I);} Printf ("/ NDO You Want To try it again? (/" Yy / ". OR ./" n / ") / n"); if (((( C = getCH ()) == 'y') goto loop;} ================ ============================================== 【程序 程序 95】 Topic: Home Financial Management Apprassment 1. Program Analysis: 2. Source Code: / * Money Management System * / # include "stdio.h" #include "dos.h" main () {file * fp; struct date d ;

Float SUM, CHM = 0.0; INT LEN, I, J = 0; INT C; CHAR CH [4] = "", CH1 [16] = "", Ch Time [12] = "", Chshop [16], Chmoney [8]; PP: CLRSCR (); SUM = 0.0; gotoxy (1, 1); Printf ("| ----------------------- -------------------------------------------------- | "); gotoxy (1, 2); Printf (" | Money Management System (C1.0) 2000.03 | "); gotoxy (1, 3); Printf (" | ----------- -------------------------------------------------- -------------- | "); gotoxy (1, 4); Printf (" | - Money Records - | - Today Cost List - | "); gotoxy (1 , 5); Printf ("| --------------------------- --------------------------------------- - | | |); Gotoxy (1,7); Printf ("| | | | |"); gotoxy (1, 8); printf ("| -------------- | "); gotoxy (1, 9); Printf (" | THGS: ------------------ | | "); gotoxy (1, 10); Printf (" | | | | | "); Gotoxy (1,11); Printf (" | ---------------- | | "); gotoxy (1,12); printf ("| COST: ---------- | |"); gotoxy (1, 13); Printf ("| | | | |"); gotoxy (1,14); printf ("| --------- | | "); gotoxy (1,15); Printf (" | | | "); gotoxy (1, 16); Printf (" | | | "); gotoxy (1, 17); Printf ("| | | | "); gotoxy (1,18); printf (" | | | "); gotoxy (1,19); printf (" | | | "); gotoxy (1, 20); printf (" | | | | "); gotoxy (1,21); printf (" | | | "); gotoxy (1,22); Printf (" | | | "); gotoxy (1, 23); printf (" | ---- -------------------------------------------------- --------------------- | "); i = 0; getdate (& D); sprintf (chtime,"% 4D.% 02d.% 02d ", D .da_year, d.da_mon, d.da_day); for (;;) {gotoxy (3, 24); Printf ("tab __browse cost list esc __quit"); gotoxy (13, 10); Printf (");" GotoxY (13, 13); Printf (""); gotoxy (13, 7); Printf ("% s"

, chtime); J = 18; CH [0] = getCH (); if (CH [0] == 27) Break; strcpy (chshop, ""); strcpy (chmoney, "); if (ch [0 ] == 9) {mm: i = 0; fp = fopen ("HOME.DAT", "R "); gotoxy (3,24); printf (""); gotoxy (6, 4); Printf (" List records "); gotoxy (1,5); printf (" | -------------------------------- --- | "); Gotoxy (41, 4); Printf (" "); gotoxy (41, 5); Printf (" | "); while (fscanf (fp,"% 10S% 14S% F / N " , chtime, chshop, & chm)! = EOF) {if (i == 36) {getCH (); i = 0;} IF ((i% 36) <17) {gotoxy (4, 6 i); printf (""); gotoxy (4,6 i);} elseif ((i% 36)> 16) {gotoxy (41, 4 i-17); Printf (""); gotoxy (42, 4 i -17);} i ; sum = sum CHM; Printf ("% 10S% -14S% 6.1f / n", chtime, chshop, chm);} gotoxy (1, 23); printf ("| -------------------------------------------------- ---------------------- | "); gotoxy (1,24); Printf (" | | "); gotoxy (1,25); Printf "| ------------------------------------------------------------------------------- --------------------------- | "); gotoxy (10,24); Printf (" Total IS% 8.1F $ ", SUM ); fclose (fp); gotoxy (49, 24); Printf ("press any key to ....."); getCh (); goto pp;} else {while (ch [0]! = '/ r ') {IF (j <10) {strncat (chtime, ch, 1); J ;} if (ch [0] == 8) {LEN = Strlen (chtime) -1; IF (j> 15) {len = len 1; j = 11;} strcpy (ch1, "); j = j-2; strncat (ch1, chtime, len); strcpy (chtime, ""); strncat (chtime, ch1, len-1); gotoxy (13, 7); Printf ("");} gotoxy (13, 7); Printf ("% s", chtime); ch [0] = getCH (); if (CH [0] == 9) goto mm; if (CH [0] == 27) exit (1);} gotoxy (3,24); Printf (""); gotoxy (13, 10); j = 0; CH [0] = getCH (); while (ch [= 0]! = '/ r') {IF (j <14) {strncat (chshop, ch, 1); J ;

} IF (CH [0] == 8) {LEN = Strlen (chshop) -1; strcpy (ch1, "); j = j-2; strncat (chshop, len); strcpy (chshop," ); strncat (chshop, ch1, len-1); gotoxy (13, 10); Printf ("");} gotoxy (13, 10); Printf ("% s", chshop); ch [0] = getCH (); gotoxy (13, 13); j = 0; CH [0] = getCH (); while (ch [0 (= 0]! = '/ r') {IF (j <6) {strncat (chmoney, ch , 1); J ;} IF (CH [0] == 8) {LEN = Strlen (chmoney) -1; strcpy (ch1, "); j = j-2; strncat (ch1, chmoney, len); Strcpy (chmoney, "); strncat (chmoney, ch1, len-1); gotoxy (13, 13); Printf (" ");} gotoxy (13, 13); Printf ("% s ", chmoney); CH [0] = getCH ();} = 0) || (Strlen (chmoney) == 0)) Continue; IF ((fp = fopen ("home.dat", "A "))! = Null); FPRINTF (FP,"% 10S% 14S% 6S ", chtime, chshop, chmoney; fputc ('/ n', fp); fclose (fp); i ; gotoxy (41, 5 i); Printf ("% 10S% -14S% -6s", chtime, chshop, chmoney);}}} ======================== ======================================= 【程序 9 96】 Title: Computing string neutron The number of strings appears 1. Program analysis: 2. Source code: #include "string.h" #include "stdio.h" main () {char str1 [20], str2 [20], * p1, * p2; INT SUM = 0; Printf ("please input two strings / n"); scanf ("% S% S", STR1, STR2); P1 = STR1; P2 = STR2; while (WHILE) * p1! = '/ 0') {if (* p1 == * p2) {while (* p1 == * p2 && * p2! = '/ 0') {p1 ; p2 ;}} elsep1 ; if (* p2 == '/ 0') SUM ; p2 = str2;} printf ("% d"

, SUM); getCH ();} ========================================= ===================== 【Program 97】 Topic: Enter some characters from the keyboard, send them onto the disk until it is entered. 1. Program analysis: 2. Program source code: #include "stdio.h" main () {file * fp; char ch, filename [10]; scanf ("% s", filename); if ((fp = fopen) (Filename, "W")) == null) {PrintF ("canNot Open file / n"); exit (0);} ch = getchar (); ch = getchar (); while (ch! = '#' ) {FPUTC (CH, FP); PUTCHAR (CH); CH = getchar ();} fclose (fp);} ======================= ============================================================================================== 【Program 98】 Strings, convert all lowercase letters into uppercase letters, then output to a disk file "Test" saved. Entered string! end.

1. Program analysis: 2. Source code: #include "stdio.h" main () {file * fp; char STR [100], filename [10]; int i = 0; if ((fp = fopen) TEST "," W ")) == null) {PrintF (" Cannot Open THE FILE / N "); exit (0);} Printf (" Please Input A String: / N "); Gets (STR); while (Str! = '!) {IF (Str> =' a '&& str = STR-32; FPUTC (STR, FP); i ;} fclose (fp); fp = fopen (" TEST "," R "); FGETS (STR, STRLEN (STR) 1, FP); Printf ("% S / N ", STR); fclose (fp);} ========== ============================================================================================================================================================================================================= == [Program 99] Title: There are two disk files A and B, and each of them stores a line of letters, requiring mergers in the two files (in alphabetical order), output to a new file C.

1. Program analysis: 2. Source code: #include "stdio.h" main () {file * fp; int i, j, n, ni; char C [160], t, ch; if ((fp = FOPEN ("A", "R")) == NULL) {Printf ("File A Cannot Be Opened / N"); exit (0);} Printf ("/ N a contents are: / n"); for (i = 0; (CH = FGETC (FP))! = EOF; i ) {c = ch; putchar (c);} fclose (fp); ni = i; if ((fp = fopen ("b", "r")) == null) {Printf ("file b cannot be opened / n"); exit (0);} Printf ("/ n b contents are: / n"); for (i = 0; CH = FGETC (FP))! = EOF; i ) {c = ch; putchar (c);} fclose (fp); n = i; for (i = 0; i c [j]) {t = C; c = c [j]; c [j] = t;} printf ("/ n c file is: / n" ); fp = fopen ("c", "w"); for (i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-124169.html

New Post(0)