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