-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.c
More file actions
60 lines (50 loc) · 1.54 KB
/
PrimeNumber.c
File metadata and controls
60 lines (50 loc) · 1.54 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
60
#include <stdio.h> // Standard Library File aka Header File
int main(void)
{
/* ---------------------- */
// Declarations
int Maxlimit;
int toDivided;
int i; // Parent Loop Variable
int t; // Child Loop Variable
/* ---------------------- */
// Asks User for Input the Number til that you want to Print all Prime Numbers
printf("Enter Max Limit: ");
scanf("%d", &Maxlimit);
/* ---------------------- */
// Checking that user entered Number must be above from 0
if (Maxlimit > 0)
{
// Parent Loop Starts
for (i = 1; i <= Maxlimit; i++)
{
if (i == 1 || i == 2 || i == 3)
{
printf("%d\n",i);
}
else if (i % 2 != 0)
{
int p = 0; // Most Important Variable Declaration
// Child Loop Starts
for (t = 2; t <= (i / 2); t++)
{
if (i % t == 0)
{
p = 1;
break;
}
}
if (p == 0)
{
printf("%d\n",i);
}
}
}
}
// When user entered zero or less than zero
else
{
printf("There is no Prime Number below from 1");
}
return 0;
}