-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem-35.c
49 lines (45 loc) · 969 Bytes
/
problem-35.c
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
/**
* @file problem-35.c
* Create a user defined function prime() which will return the status of an inputted number wither thatis prime or not prime.
* @author Md. Alamin ([email protected])
* 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-03-31
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
int prime(int a);
void main()
{
int isPrime, n;
printf("Enter a number: ");
scanf("%d", &n);
isPrime = prime(n);
if (isPrime != 0)
{
printf("%d is prime\n", n);
}
else
{
printf("%d is not Prime.\n", n);
}
}
int prime(int a)
{
int i;
if (a <= 1)
{
return 0;
}else{
for (i = 2; i <= a / 2; i++)
{
if (a % i == 0)
{
return 0;
}
}
return 1;
}
}