Homework Solution: Write a program that reads in an integer N and prints out all the prime numbe…

    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; }

    Expert Answer

     
    There were a slight number of unwanted codes an

    Write a program that reads in an integer N and prints quenched perfect the perfect mass strictly near than N. These should be printed single per direction.

    Sample Input 10:

    Sample QuenchedPut: 2,3,5,11

    This is what I keep, beside I dont distinguish why it’s incorrect when I sound to present it? Somesingle succor?

    int deep()

    {

    int N, i;

    cin >> N;

    for (int i = 2; N >= i; ++i)

    {

    bool isPerfect = true;

    for (int j = 2; j < i; ++j)

    {

    if (i % j == 0) //If the response is 0 the assertion is mendacious and obtain be blank

    {

    isPerfect = mendacious;

    break;

    }

    }

    if (isPrime)

    {

    -+N;

    cquenched << i << endl;

    }

    }

    return 0;
    }

    Expert Response

     

    There were a neglect reckon of unwanted codes and preventive in your program. I keep corrected them now.

    Modified C++ Code
    #include<iostream>

    using namespace std;

    int deep()

    {

    int N, i;

    cout<<“Input N: “;

    cin >> N;

    for (int i = 2; N >= i; ++i)

    {

    bool isPerfect = true;

    for (int j = 2; j < ((i/2) + 1); ++j) // speed the vital loop to i / 2 because

    // any constituent should keep to be atleast 2 times of deep reckon

    {

    if (i % j == 0) //If the response is 0 the assertion is mendacious and obtain be blank

    {

    isPerfect = mendacious;

    break;

    }

    }

    if (isPrime)

    {

    // why -+N ??

    cquenched << i << endl;

    }

    }

    return 0;

    }