I was trying to write a C++ code to find if the entered number is prime or not. There is a big logic problem in the code which I have failed to fix. At least you can see I tried. Now please help me with it. It would be kind of you.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int n, i;
bool prime = true;
cout << "Enter the number: ";
cin >> n;
for (i=2; i<=(n/2);i++)
{
if (n%i != 0)
prime = true;
else if (n%i = 0)
prime = false;
{
if (prime = false)
break;
}
}
if (prime = true)
cout << "the number is prime" << endl;
else
cout << "not prime" << endl;
system("pause");
}


Sign In
Create Account

This topic is locked

Back to top










