Continue to interpret putchar, getchar (the ASCII code value of \n is 10)
spaces and carriage returns will not be automatically cleared, still
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
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
and is recommended for loop, because for loop code readability relatively high
semicolon between expression and expression note;
for loop execution flow
break; the three cycles are the same
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
modifying the variable may cause an endless loop.
Note that the assignment is = judgment is ==
recommended: the front is a closed interval, and the back is an open interval. Enhanced code
according to the situation
readability
in front of a closed interval, followed by a closed interval
some of the for loop variants of
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
you omit
it, you can omit it. In this case, after the outer layer loops once, j=10, but j will not be reset to 0;
it is recommended not to omit it.
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
break is the same.
Note that
continue will jump directly After the code behind this cycle, come back to do and execute the code directly. The
loop knowledge points are summarized and the
exercise starts
. 1. Calculate the n-th power
of i 2. Calculate the factorial
idea of i : cumulative multiplication
brute force search
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.
Example:
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
Recommended
Ranking