-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor_while_prime.c
51 lines (48 loc) · 919 Bytes
/
for_while_prime.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
#include <stdio.h>
int main()
{
int limit, i = 3, for_count, wh_count, num;
printf("Enter the limit:");
scanf("%d", &limit);
printf("Prime nos using for loop\n");
if (limit >= 1)
{
printf("2 ");
}
for (for_count = 2; for_count <= limit; i++)
{
for (num = 2; num < i; num++)
{
if (i % num == 0)
break;
}
if (num == i)
{
printf("%d ", i);
for_count++;
}
}
printf("\nPrime nos using while loop\n");
if (limit >= 1)
{
printf("2 ");
}
wh_count = 2;
i = 3;
while (wh_count <= limit)
{
num = 2;
while (num < i)
{
if (i % num == 0)
break;
num++;
}
if (num == i)
{
printf("%d ", i);
wh_count++;
}
i++;
}
}