-
Notifications
You must be signed in to change notification settings - Fork 2
/
newPrime.c
59 lines (40 loc) · 886 Bytes
/
newPrime.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
58
/************** next Prime number************************************************
************** Generates next prime number on the basis of user input************
************** by Bhavika******************************************************/
# include <stdio.h>
# include <stdbool.h>
int nextprime(int);
int
main()
{
int val=1;
char input;
do
{
val=nextprime(val);
printf("%d\t",val);
printf("Next Prime number? Y or N ");
scanf(" %c",&input);
}
while(input != 'N' && input != 'n');
return 0;
}
int nextprime(int val)
{
val++;
int i=2;
while(i<val)
{
if(val%i==0)
{
val++;
i=2;
continue;
}
else
{
i++;
}
}
return val;
}