Actually, I don't understand why there are two while loops, one should be enough.
Typically in this sort of program, the decision that the number is not prime can be made as soon as any remainder of zero is found, that's the easy test. To find that it actually is prime usually the loop needs to progress right through to the end. If it wasn't found to be "not prime" then by default it must be prime.
When I say "progress right through to the end" I mean test for division by every number apart from 1 and the number itself.
#include <iostream>
#include <conio.h>
usingnamespace std;
int main()
{
longunsignedint a,b;
clrscr();
cout<<"Enter the number"<<endl;
cin>>a;
for (b=2; b<a; b++)
{
if ((a%b) == 0)
{
cout<<"It is not a prime number";
goto stop;
}
}
cout<<a<<" is a prime number";
stop:
getch();
}
If the program needs to be extended, I'd recommend making a separate function called bool isPrime(unsignedlong); or similar, which takes an integer parameter and returns a bool result to indicate whether the number is prime or not.
That way, you can build whatever additional code you like in main() and just call the function as required.