-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathp3final.c
More file actions
48 lines (45 loc) · 677 Bytes
/
p3final.c
File metadata and controls
48 lines (45 loc) · 677 Bytes
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
/*
Write a program find whether a given number is a prime number.
int input_number();
int is_prime(int n);
void output(int n, int is_prime);
*/
#include <stdio.h>
#include <math.h>
int input()
{
int n;
printf("Enter the number\n");
scanf("%d",&n);
return n;
}
int isprime(int n)
{
if (n==0 || n==1) {
return 0
}
if (n==2) {
return 1;
}
for(int i= 2; i<= sqrt(n);i++)
{
if(n%i==0)
return 0;
}
return 1;
}
void output(int n, int isp)
{
if(isp == 0)
printf("%d is not a prime number\n",n);
else
printf("%d is a prime number\n",n)
}
int main()
{
int n = input();
int isp = isprime(n);
output(n,isp);
return 0;
}
}