Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago