Print the prime number between 100 and 200 in C Language

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.