forked from AkshayNachappa/Hacktoberfest_101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primitive_numbers.c
58 lines (41 loc) · 910 Bytes
/
Primitive_numbers.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
56
57
#include <stdio.h>
#include <stdlib.h>
void primitiveNumbers_upto_n(int n);
int check_for_primitive(int aNumber);
int main()
{
//requiring the n
int n;
printf("Enter Number : ");
scanf("%d", &n);
//primitive numbers upto that
primitiveNumbers_upto_n(n);
return 0;
}
void primitiveNumbers_upto_n(int n){
if(n==1||n==0)
{
printf("no primitive numbers");
}
else{
printf("From 1 to %d primitive numbers are : \n",n);
for(int i=2; i<=n ;i++)
{
if(check_for_primitive(i)== 1)
{
printf("%d \t", i);
}
}
}
}
int check_for_primitive(int aNumber){ //only return a value if it is primitive
int count = 0;
for(int i=2; i<=aNumber/2; i++){
if(aNumber%i==0){
count++;
}
}
if(count==0){
return 1;
}
}