hi all,
I am new here,and I wish I could find a solution for this program
My program has to check if the number is prime or not?,
my program is working properly with numbers greater than 1 (n>1),
I want my program to display a friendly message when the user enter number (0) or (1) and then stop the program.
please Help,I tried many times to try to solve this problem but I couldn't !,,
mY hOmework is due on Saturday 29 Dec,
Please Help me
and this is my code :
#include <iostream>
using namespace std;
void main()
{
int x, y;
int z=0;
cout << "Please Enter a positive number\n";
cin >> x;
for (y = 2; y<x; y++)
{
if ((x % y) == 0)
{
z=1;
break;
}
}
if (z==1)
cout << "Not prime number\n";
else
cout << "prime number\n";
}
The problem with my program is when the user enter number 0 or 1 , it outputs is prime number:'( ,0 and 1 ARE NOT PRIME NUMBERS,,please help me and thanks for ur efforts