-
Notifications
You must be signed in to change notification settings - Fork 1
/
Q-06.c
55 lines (35 loc) · 771 Bytes
/
Q-06.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
50
51
52
53
54
55
#include<stdio.h>
int checkPrime(int x);
void printPrime(int range_start, int range_end);
void main(){
int n,i;
printf("Enter a number: ");
scanf("%d",&n);
if(checkPrime(n))
printf("%d is a prime number!\n",n);
else
printf("%d is not a prime number!\n",n);
printf("\nPrinting all Prime Numbers upto 100: \n");
printPrime(1,100);
}
int checkPrime(int x) {
int i;
if(x==1 || x==0) // So that Program won't crash
return 0;
else {
for(i=2; i <= x/2; i++) {
if(x%i==0) {
return 0;
}
}
}
return 1;
}
void printPrime(int range_start, int range_end) {
int i;
for(i=range_start; i <= range_end; i++) {
if(checkPrime(i)==1){
printf("%d ",i);
}
}
}