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