[Program 11] Topic: Classical question: There is a pair of rabbits, from the third month after birth, a bunny every month, the bunny is born again 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 12】 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);} = ============================================================================================================================================================================================================= =========== 【Program 13】 Title: Print all "Number of daffodils", the so-called "Number of Narcies" refers to a three-digit number, and its digital cubes and equal mids 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 14] 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);} ========================== ============================================== 【Procedure 15】 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);} =================== =================================================== 【program 16】 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 17] Title: Enter a line of characters, statistics, respectively, 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 18] 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.