A circulation
1, while loop, "when the" cycle
notice: have the opportunity to change the conditions of the loop body, otherwise it is an endless loop.
It is possible to execute the cycle once did.
tips: sheet running a simulation program, write a variable change, or insert the appropriate place in the program printf
exam:x n
10 0
1 1
0 2
pro1: the number of digits
debugging
2, do-while loop
Recycling at least do it again
Enter 0 Debugging
N = 1 the correct final result
tips: To circulate calculated to preserve the original value before the calculation, may be followed by
pro2: guessing game
Every call rand () to get a random integer
pro3: average count
pro4: integer reverse
The factoring integers
3, for the cycle (the initial operation; continue cycling conditions; cycle round actions to be done)
for (; condition;) == while (condition)
pro5: factorial
ques1: What cycle when the election?
tips: There are a fixed number for, you must perform a do-while, while other cases with
Second, the control loop
pro1: determining whether a number is a prime number
break: out of the loop
continue: skip the rest of this round cycle statement to the next round
It can only do that layer where the cycle
gram2: prime number within the output 100
Third, the nested loop
gram3: the first 50 prime numbers Output
pro4: Minato coins How angle 1, angle 2, and 5 coin angle 10 yuan amount Couchu
Relay break:
goto: leave out all the local loop jump within the meaning of the innermost nested for loop jumps out most other places is not recommended
pro4:f(n)=1+1/2+1/3+1/4+...+1/n
Start: 1, end: n, are clear, it is suitable for use
pro5:f(n)=1-1/2+1/3-1/4+...+1/n;
pro6: positive sequence factoring integers
Enter a non-negative integer, its positive sequence output each digit.
Input: 13245
Output: 13245
Option One: to reverse and then reverse, not only for the number 0 at the end.
Seemingly perfect, but! ! !
Option II:
13425/10000-->1
13425%10000-->3425
10000/10-->1000
3425/1000-->3
3425%1000-->425
1000/10-->100
425/100-->4
425%100-->25
100/10-->10
25/10-->2
25%10-->5
10/10-->1
5/1-->5
5%1-->0
1/10-->0
but!!!
pro7: greatest common divisor
Algorithm 1: Enumeration
Algorithm 2: Euclidean
Variable table analysis method:
a b t
12 18 12
18 12 6
12 6 0
6 0