Question: Problem 2 ( Primes ) A positive integer is prime if its only positive divisor is 1 or itself. For example, 2 , 3 ,

Problem 2(
Primes
)
A positive integer is prime if its only positive divisor is 1 or itself. For example, 2,3,5,
and 7 are prime numbers, but 4,6,8, and 9 are not. Write a program named
primes.cpp
that allows the user to enter a value
N
(int) from keyboard. Computes and displays
N
first
primes. Your program must show the message
Please enter N >0
if the user entered
an invalid value.
/workspace/csc117/hw7
% g++-o out/primes.out src/primes.cpp
%./out/primes.out
Enter the value of N: 16
The first 16 primes are: 2357111317192329313741434753
%./out/primes.out
Enter the value of N: -5
Please enter N >0
Hint:
You should make two loops (the outer and and the inner ones)
The outer loop is used to check if you have printed out
N
primes
The inner loop is used to check whether or not a number is a prime? if it is a prime,
then print it out and increase the couter of outer loop.
Noted that, 1 is not considered a prime

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!