Programming exercises for the 4th week of C programming (prime number and)

Source: Internet
Author: User

1 primes and (5 points)

Topic content:

We think 2 is the first prime number, 3 is the second Prime, 5 is the third prime, and so on.

Now, given the two integers n and m,0<n<=m<=200, your program calculates the number of primes between the nth prime number and the number of M primes, including the nth Prime and the first M prime.

Input format:

Two integers, the first representing N, and the second represents M.

Output format:

An integer representing the nth prime number and the number of primes between the first m primes, including the nth Prime and the first M prime.

Input Sample:

2 4

Sample output:

15

Progress: Conscious use of logical expressions when using an if () statement is more concise.

Core: Use if (count>=n&&count<=m) {} to calculate the number of nth primes to the number of M primes.

Trial and error process: In the 12th debugging, the discovery has always appeared i=2, as well as count=1,count=2,count=2,count=2 ...

Later found that the original variable initialization was misplaced (put i=2 in the first sentence of Loop 1, put isprime=1 in front of the loop). I=2 should be placed in front of the loop, and isprime=1 should be placed in the loop inside the first sentence, or every time the loop is i=2, and when i=4, Isprime=0, IsPrime has been equal to 0. Causes an error.

Programming exercises for the 4th week of C programming (prime number and)

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.