Sunday, 8 January 2017

To find prime no by function in C++

#include<iostream.h>
#include<conio.h>
int prime(int x);
void main()
{
clrscr();
int a,c;
cout<<"enter any number ";
cin>>a;
c=prime(a);
if(c==2)
cout<<"prime";
else
cout<<"not prime";
getch();
}
int prime(int x)
{
int d=0,f;
for(int i=1;i<=x;i++)
{
if(x%i==0)
d++;
}
return d;
}

No comments:

Post a Comment