C Program to check prime numbers using recursion

Simple C Program to check whether a number is prime number or not. A number is called prime number which is divisible only by 1 and itself. For example number 5 is prime number because it is divisible by 1 and 5 but number 8 is not prime number because it is divisible by 2,4.
/* C program to check prime number */
#include<stdio.h>
void FindPrime(int num,int n)
{
 if(n==1)
 {
 printf("Number is prime\n");
 return ;
}
 if(n==0||num%n==0)
 {
  printf("Number is not prime: ");
  return ;
 }
 FindPrime(num,n-1);
}
int main()
{
 int num;
 printf("Enter a number: ");
 scanf("%d",&num);
 FindPrime(num,num-1);
 return 0;
}
/* End of the program */
 

Popular posts from this blog