Question: Programming Assignment # 5 - - ( Calculate the nth Prime Number ) Due: _ see canvas Name your program: p 5 . c This

Programming Assignment #5--(Calculate the nth Prime Number)
Due:_see canvas
Name your program: p5.c
This week we are going to simplify last weeks program with the use of a
Function. The code below is the code shown in class last week. This week we
need to replace the code in the black rectangle with a function called,
check_if_prime();
#include
#define TRUE 1
#define FALSE 0
//function prototype goes here
int main (void){
unsigned int nth_prime, number_of_primes;
unsigned int test_int, divisor;
_Bool isPrime;
printf("Enter the nth_prime to find:");
scanf("%u", &nth_prime);
number_of_primes =0;
test_int =1;
do
{
test_int++;
isPrime=TRUE; //assume test_int is prime until proven not to be
for(divisor =2; divisor < test_int; divisor++)
{
if(test_int % divisor ==0)
{
isPrime = FALSE;
break;
}
}
if(isPrime == TRUE)
number_of_primes++;
}
while( number_of_primes < nth_prime );
printf("The %u Prime Number =%u
", nth_prime, test_int);
return 0;
}
The function definition should look like:
_Bool check_if_prime( unsigned int test_number)
{
// code to determine if a number is prime, goes here
}
This function takes an (unsigned int) as an argument, and returns 0(i.e. false) if
the integer is not prime, and returns 1(for true) if the integer is prime.
Once youve completed your program, fill in the table below.
600 th Prime Number is: 6,000th Prime Number is: 60,000th Prime Number is:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!