int testprime(int ,int);
void main()
{
int n,prime;
printf("Enter a positive number : ");
scanf("%d",&n);
prime=testprime(n,n/2);
if(prime==1)
printf("%d is prime number.",n);
else
printf("%d is not a prime number.",n);
getch();
}
int testprime(int num, int i)
{
if(i==1)
{
return 1;
}
else
{
if(num%i==0)
{
return 0;
}
else
{
testprime(num,i-1);
}
}
}
0 comments:
Post a Comment