Prime number simple error

if i substitute with a=1 and then counts==2 its working, but not with this logic, whats wrong in it?


#include<iostream.h>
#include<conio.h>
void main()
{
//clrscr();
int number,count=0;
cout<<"ENTER NUMBER TO CHECK IT IS PRIME OR NOT ";
cin>>number;
for(int a=2;a<=number;a++)
{
if(number%a==0)
{
count++;
}
}
if(count==0)
{
cout<<" PRIME NUMBER \n";
}
else
{
cout<<" NOT A PRIME NUMBER \n";
}
//getch();
}
Simple enough for you to figure out for your self that
for every number X >= 2, count >= 1
This is because of your condition, a <= number
when a reaches number, number%a == 1
Topic archived. No new replies allowed.