Classic C language procedure 100 cases (1-10) ---------------- Transfer from C Language Classics Forum

xiaoxiao2021-03-06  46

[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; 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);}

============================================================================================================================================================================================================= ============ 程序 程序 3] Title: an integer, it is 100 after 100 is a full level, 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);} } ==================================================== ============= 【Procedure 4】 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 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 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 6】 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");} =========================== ============================================ 【程序 7 7】 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 8】 Title: Output 9 * 9 oral 诀. 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 9】 Title: Requires an 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.

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

New Post(0)