Check Prime number or Not by using Function
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int prime(int x);
int n,flag;
printf("Enter the number: ");
scanf("%d",&n);
flag=prime(n);
if(flag==1)
printf("\n Yes!! %d is Prime number \n",n);
else
printf("\n No!! %d is not Prime number \n",n);
}
int prime(int x)
{
int i,a;
a=sqrt(x);
if((x==1)||(x==2))
return(0);
else
{
for(i=2;i<=a;i++)
if(x%i==0)
return(0);
return(1);
}
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int prime(int x);
int n,flag;
printf("Enter the number: ");
scanf("%d",&n);
flag=prime(n);
if(flag==1)
printf("\n Yes!! %d is Prime number \n",n);
else
printf("\n No!! %d is not Prime number \n",n);
}
int prime(int x)
{
int i,a;
a=sqrt(x);
if((x==1)||(x==2))
return(0);
else
{
for(i=2;i<=a;i++)
if(x%i==0)
return(0);
return(1);
}
}
No comments:
Post a Comment