Question: Problem 2 ( Primes ) A positive integer is prime if its only positive divisor is 1 or itself. For example, 2 , 3 ,
Problem
Primes
A positive integer is prime if its only positive divisor is or itself. For example,
and are prime numbers, but and 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
if the user entered
an invalid value.
workspacecschw
go outprimesout srcprimescpp
outprimesout
Enter the value of N:
The first primes are:
outprimesout
Enter the value of N:
Please enter N
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, is not considered a prime
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
