Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 // next immdiate prime number using do while
- 2 #include <stdio.h>
- 3 int main()
- 4 {
- 5 int num,i,j=1,count=0;
- 6 scanf("%d",&num);
- 7 i = num+1; //checking from next number
- 8 do
- 9 {
- 10 do
- 11 {
- 12 if(i%j==0)
- 13 {
- 14 count++; //counting number of factors of a number
- 15 }
- 16 if(count >2)
- 17 {
- 18 continue;
- 19 }
- 20 j++;
- 21 }while(j<=i);
- 22 if(count ==2)
- 23 {
- 24 printf("%d",i);
- 25 return 0;
- 26 }
- 27 count=0;
- 28 j=1; // setting the j flag
- 29 i++;
- 30 }while(1); // infinite loop until next immediate prime is found
- 31
- 32 return 0;
- 33 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement