===========================================================================
CODING
#include<all.h>
void main()
{
clrscr();
int n,i,sum;
cout<<"Enter no. for checking for prime no.: ";
cin>>n;
for(i=2,sum=0;i<=sqrt(n);i++)
{
if(n%i==0)
sum=sum+i;
else
sum=sum+0;
}
if(sum==n+1)
cout<<"\n"<<n<<" is a Prime number";
else
cout<<"\n"<<n<<" is not a Prime number";
getch();
}
CODING
#include<all.h>
void main()
{
clrscr();
int n,i,sum;
cout<<"Enter no. for checking for prime no.: ";
cin>>n;
for(i=2,sum=0;i<=sqrt(n);i++)
{
if(n%i==0)
sum=sum+i;
else
sum=sum+0;
}
if(sum==n+1)
cout<<"\n"<<n<<" is a Prime number";
else
cout<<"\n"<<n<<" is not a Prime number";
getch();
}
===========================================================================
No comments:
Post a Comment