Branch and loop (two) (zero-based learning C language)

Continue to interpret putchar, getchar (the ASCII code value of \n is 10)
Branch and loop (two) (zero-based learning C language)
spaces and carriage returns will not be automatically cleared, still
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
remember to put parentheses in the buffer , the priority is different,
this is a good way to only print 1- 9 (using continue) a way that requires input
Branch and loop (two) (zero-based learning C language)
2. for loop (while loop and do while loop can be transformed into for loop)
The initialization of for loop conditions will only be executed once
while loop requires special attention to the initialization of loop conditions and loop variables adjustment
Branch and loop (two) (zero-based learning C language)
and is recommended for loop, because for loop code readability relatively high
Branch and loop (two) (zero-based learning C language)
semicolon between expression and expression note;
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
for loop execution flow
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
break; the three cycles are the same
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
but requires special attention to the Continue
the Continue is End the loop.
Skip the code behind continue and go directly to the judgment part of the condition.
Note that
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
modifying the variable may cause an endless loop.
Note that the assignment is = judgment is ==
Branch and loop (two) (zero-based learning C language)
recommended: the front is a closed interval, and the back is an open interval. Enhanced code
according to the situation
Branch and loop (two) (zero-based learning C language)
readability
Branch and loop (two) (zero-based learning C language)
in front of a closed interval, followed by a closed interval
Branch and loop (two) (zero-based learning C language)
some of the for loop variants of
Branch and loop (two) (zero-based learning C language)
the three conditions for loop can be omitted,
but if the judge for a conditional loop is omitted, indicating the condition of constant judgment is true, the endless loop
is not recommended If
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
you omit
Branch and loop (two) (zero-based learning C language)
it, you can omit it. In this case, after the outer layer loops once, j=10, but j will not be reset to 0;
Branch and loop (two) (zero-based learning C language)
it is recommended not to omit it.
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Judgement condition is 0, don’t enter the loop,
assign =, judge as ==
3. do while loop
characteristics: the loop must be executed at least once.
Note: after the while (judgment statement); no less
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
break is the same.
Branch and loop (two) (zero-based learning C language)
Note that
continue will jump directly After the code behind this cycle, come back to do and execute the code directly. The
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
loop knowledge points are summarized and the
exercise starts
. 1. Calculate the n-th power
Branch and loop (two) (zero-based learning C language)
of i 2. Calculate the factorial
idea of i : cumulative multiplication
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
brute force search
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
binary search (guess number game) The method: narrow the range and compare with the intermediate value) at
most search log2n times
must be a number that has been arranged in order.
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Example:
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
Branch and loop (two) (zero-based learning C language)
strcmp (string 1, string 2)
string comparison function, is a library function, need the header file #include <string.h>
If string 1 is equal to string 2, then this function returns 0.
If string 1 has more characters than string 2, then this function returns a number greater than 0.
If string 1 has fewer characters than string 2. Character then this function returns a number less than 0
Branch and loop (two) (zero-based learning C language)

Guess you like

Origin blog.51cto.com/15083388/2605005