151. Design a function to check given input is prime or not. If prime return 1 else return 0.
#include<stdio.h>
int
prime(int);
int
num,r;
void
main()
{
printf("Enter a number :");
scanf("%d",&num);
r=prime(num);
if(r==1)
printf("Prime Number\n
");
else
printf("Not a Prime
Number\n ");
}
int
prime(int n)
{
int i;
for(i=2;i<n;i++)
{
if(n%i==0)
break;
}
if(i==n)
return 1;
else
return 0;
}
Comments
Post a Comment