how do i print out

Oct 23, 2017 at 6:36am
ive created a program that'll out the output prime numbers from the users input but i dont know how to tell the user whether the number is prime. pls help :'(

cout << "Enter a number ----> : " << endl;
cin >> num;
int i, j, primeNum;
for(i = 2; i < 102; i++)
{
primeNum = 0;
// Check whether i is prime or not
for(j = 2; j < num; j++)
{
if(i % j == 0)
{
primeNum= 1;
break;
}
}
if(primeNum == 0)
{
cout << i << " ";
}
}
Oct 23, 2017 at 8:07am
i dont know how to tell the user whether the number is prime


When it's prime, output "The number is prime".
When it's not prime, output "The number is not prime".
Oct 23, 2017 at 8:08am
The logic looks a bit mixed-up.
If the user inputs the number 7 or lower, some of the numbers output are not prime.

Enter a number ----> :
5
5 7 11 13 17 19 23 25 29 31 35 37 41 43 47 49 53 
55 59 61 65 67 71 73 77 79 83 85 89 91 95 97 101
Topic archived. No new replies allowed.