Slyfoxx724

p4.c

Dec 7th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. 1 #include <stdio.h>
  2. 2 int main(void)
  3. 3 {
  4. 4 unsigned int number_of_primes, test_int, latest_prime, div, input;
  5. 5 _Bool isPrime;
  6. 6 #define TRUE 1
  7. 7 #define FALSE 0
  8. 8
  9. 9 test_int = 1;
  10. 10 number_of_primes = 0;
  11. 11
  12. 12 printf("For which prime number do you want to know the value?\n");
  13. 13 scanf("%u", &input);
  14. 14
  15. 15 do
  16. 16 {
  17. 17 test_int++;
  18. 18 isPrime = TRUE;
  19. 19 for(div=2; div < test_int; div++)
  20. 20 {
  21. 21 if(test_int%div == 0)
  22. 22 {
  23. 23 isPrime = FALSE;
  24. 24 break;
  25. 25 }
  26. 26 }
  27. 27 if(isPrime == TRUE)
  28. 28 {
  29. 29 number_of_primes++;
  30. 30 latest_prime = test_int;
  31. 31 }
  32. 32 }
  33. 33 while(number_of_primes < input);
  34. 34
  35. 35
  36. 36 printf("That Prime Number = %u\n", latest_prime);
  37. 37
  38. 38 return 0;
  39. 39 }
Add Comment
Please, Sign In to add comment