100 cases of classic C procedures (1-10)

xiaoxiao2021-03-06  13

100 cases of classic C procedures (1-10)

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?

Program analysis: Fill in hundreds, ten, bit numbers are 1, 2, 3, 4. Composition all the arrangement and remove the arrangement of the conditions.

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! D,% D,% D / N ", I, J, K);}}

Title: The bonuses issued by the enterprise shall be 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?

Program analysis: Please use the number axis to be bounded and positioned. Note that the bonus will be defined to grow.

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

Title: An integer, it plus 100 is a full level, plus 168 is a complete square number, how much is this?

Program analysis: Judging within 100,000, first add 100, then re-opening, then add 268, then reopen, if the result is satisfied, that is, the result. Please see the specific analysis: program 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 after 100 after 100 * / y = SQRT (i 268); / * y is the result of the 1st after 168 after the 1st 1 * / if (x * x == i 100 && y * y == i 268) / * If the square of the square root of a number is equal to the number, this indicates that this number is complete square * / printf ("/ n% ld / n", i);}}

Topic: Enter a day in a certain year, judging this day is the first day of this year?

Program analysis: Take March 5 as an example, you should first add the first two months, then add 5 days, the first few days, special circumstances, leap year and enter the month to consider more than 3 times. .

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 / * First calculate 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 = 273; Break; Case 11: Sum = 304; Break; Case 12: Sum = 334; Break; Default: Printf ("Data Error"); Break;} SUM = Sum DAY; / * Add a 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 the month is greater than 2, the total number of days should add one day * / sum ; Printf ("IT is the% dth day.", Sum.

Title: Enter three integers x, y, z, please put these three numbers from small to large output.

Program Analysis: We want to put the minimum number to the X, first compare X and Y, if x> y swaps X and Y, then use X and Z, if x> z Then exchange the value of X and Z, which minimizes X.

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;} / * exchange x, y value * / if (x> z) {t = z; z = x; x = T;} / * swap 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);} Title: Output the pattern of the letter C with the *.

Program analysis: You can use the '*' number to write the letter C on the paper, and then the branch is output.

Source code: #include "stdio.h" main () {printf ("Hello C-World! / N"); Printf ("**** / n"); Printf ("* / n"); printf ("* / n"); Printf ("**** / n");}

Topic: Output special patterns, please run in the C environment, take a look, Very Beautiful!

Program analysis: 256 characters. Different characters, graphics are different.

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% C / N", A, B, A, B, A); Printf ("% C% C% C% C / N ", B, A, A, A, B);}

Topic: Output 9 * 9 ok.

Program analysis: Branch and column considerations, a total of 9 rows, I control line, J control column.

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-bit * /} printf (" / N "); / * Return after each line * /}}

Title: Requires the output chess board.

Program Analysis: Use I Control Row, J to control the column, control the output black square according to the change in I J, or white square.

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

Topic: Print the stairs, and print two smiles above the stairs.

Program analysis: Use I control line, j to control columns, and J control the number of output black based on changes in I.

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

New Post(0)