Print the prime number between 100 and 200 in C Language
According to the definition of prime number, only the natural number divisible by 1 and itself is a prime number. The definition can be used to cyclically determine the number divided by every natural number smaller than it (excluding 1). If no division is allowed, this number is a prime number. This method is optimized because it is too inefficient. We all know that the even number must not be a prime number, so we only need to calculate the remaining general number. If a number is a union, its minimum prime factor must be less than or equal to the square root of the number. The Union theorem can be further optimized, you only need to cyclically determine the number divided by each natural number (greater than 1) smaller than the square root of the number. The C language code is as follows:
# Include <stdio. h> # include <math. h> int main () {int m, k, I, count = 0; for (m = 101; m <= 200; m + = 2) {k = (int) sqrt (m);/* (int) sqrt (m) convert floating point type into integer */for (I = 2; I <= k; I ++) if (m % I = 0) break; if (I> k) {count ++; printf ("% d", m );}} printf ("\ ncount = % d", count); return 0 ;}
Generally, after the program enters the loop body, all statements in the loop body are executed before the next cycle judgment. The break and continue statements can terminate the loop or ignore some loops. Break: This statement causes the program to terminate the loop containing it and perform the next stage of the program (the statement following the entire loop). That is, it does not jump to the next cycle, but exits the loop. If a break statement is contained in a nested loop, it only jumps out of the innermost loop. Continue: When this statement exists in a loop statement, when the program runs this statement, it jumps to the next loop entry to execute the next loop instead of the statement following the continue in the execution loop body. If a continue statement is included in a nested loop statement, it only affects the loop at the innermost layer.