# Write a program to Check prime number using recursive function

#include <stdio.h>
#include <conio.h>
int n , e ,i ;
int prime ( int n , int i)
{
 if (n == 1 || n == 0  )
 {
 return 2;
}
 else
{
 
 if (i == 1 )
 return 0;
 else
 {
  if (n%i != 0){
   prime(n , i-1); 
  }
  else
  {
   return 1 ;
  }
  
}
}
}

int main ()
{
printf("Input a number to check whether number is prime or not: "); 
scanf("%d" ,&n);

e = prime ( n , n-1);
if (e == 0 )
printf("\nThe supplied number is  prime");
if (e == 1 )
printf("\nThe supplied number is not prime");
if (e == 2 )
printf("\nThe supplied number is neither prime nor not prime");
getch() ;
return 0 ; 
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(adsbygoogle = window.adsbygoogle || []).push({});