Navigation Bar

Prime or Not prime with while loop

#include<iostream.h>
#include<conio.h>
void main()
{
  char c = ‘y’;
  int n;
  while( c == ‘y’ || c ==’Y’ )
    {
clrscr();
cout<<” Enter a Number”<<endl;
cin>>n;
             int s = 0;

for(int i=1; i<=n; i++)
  {
            if(n%i==0)
                 s = s+1;
  }

if(s == 2)
cout<<” Prime Number”<<endl;
else
cout<<” Not Prime Number”<<endl;

cout<<” Do you want to check another number? Press ‘y’ for yes and ‘n’ for No ”<<endl;
cin>>c;
    }
getch();
}

No comments:

Post a Comment