-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeNumberRecursive.c
More file actions
59 lines (51 loc) · 1.01 KB
/
primeNumberRecursive.c
File metadata and controls
59 lines (51 loc) · 1.01 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @file primeNumberRecursive.c
* write a program to check a number is that a prime number or not using recursive function.
* @author Md. Alamin (alamin5g@yahoo.com)
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-04-06
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
int prime(int i, int n);
int main()
{
int n, f;
printf("Enter a number: \n");
scanf("%d", &n);
if (n >= 2)
{
f = prime(2, n);
if (f != 0)
{
printf("%d is prime\n", n);
}
else
{
printf("%d is not prime", n);
}
}else{
printf("%d is not prime", n);
}
return 0;
}
int prime(int i, int n)
{
if (n == i)
{
return 1;
}
else
{
if (n%i==0)
{
return 0;
}else
{
return prime(i+1, n);
}
}
}