Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Find all prime numbers between 1 and N, where N 1,000,000, and print them on screen. Prime Numbers: In mathematics, a prime number (or a

Find all prime numbers between 1 and N, where N 1,000,000, and print them on screen. Prime Numbers: In mathematics, a prime number (or a prime) is a positive integer that has exactly two divisors, which are 1 and the prime number itself. For example, 4 is not prime number because it is divisible by 1, 2, and 4. On the other hand, 5 is prime number because it is divisible only by 1 and 5. The first 30 prime numbers are 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, and 113. Algorithm: Ask user to enter N Numbers 1 and 2 are prime, print them on screen Repeat the following procedure for each number i between 3 and N: 1. Find the remainder of division of i by all numbers between 2 and i-1 (remember that operator % finds the remainder of division, e.g., 11%3 equals 2) 2. If all remainders are different from zero, the number is prime; if at least one of the remainders equals zero, the number is not prime (Hint: to save time, as soon as one of the remainders is zero, you can start examining the next number); 3. If the number is prime print it on screen.( IN C WITH COMMENTS)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Describe the importance of global talent management.

Answered: 1 week ago