Question: Write a program that reads in an integer N and prints out all the prime numbers strictly less than N. These should be printed one
Write a program that reads in an integer N and prints out all the prime numbers strictly less than N. These should be printed one per line.
Sample Input 10:
Sample OutPut: 2,3,5,11
This is what I have, but I dont know why it's incorrect when I try to submit it? Someone help?
int main()
{
int N, i;
cin >> N;
for (int i = 2; N >= i; ++i)
{
bool isPrime = true;
for (int j = 2; j < i; ++j)
{
if (i % j == 0) //If the answer is 0 the statement is false and will be blank
{
isPrime = false;
break;
}
}
if (isPrime)
{
-+N;
cout << i << endl;
}
}
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
