(Syntax) obtain all prime numbers (prime numbers) between 2 and)

Source: Internet
Author: User

Knowledge point:

Pointer used

Algorithm: except 1 and itself, if all numbers in the middle cannot be divisible by itself, this number is a prime number.

 

Content: obtain all prime numbers (prime numbers) between 2)

Input description:

None

Output description:

One prime number in a row

 

# Include <stdio. h> int main () {int I, a [100], * P, J, M; P = A; for (I = 2; I <= 100; I ++) {P = A; For (j = 2; j <I; j ++, P ++) // each I, each number J from 2 to I-1 is divided by I, and the remainder is stored in the array {* P = I % J;} p = A; // re-pointing to a [0] (; P <A + I-2; P ++) // The number of arrays is the number between 2 and I, so-2 {If (* P! = 0) // check whether the remainder has 0 {m = 0;} else // check whether the remainder is 0. If it jumps out, it does not meet M! = 1, do not output {M = 1; break;} If (M! = 1) {printf ("% d \ n", I) ;}} return 0 ;}

 

(Syntax) obtain all prime numbers (prime numbers) between 2 and)

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.