Advertisement
Guest User

Untitled

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