Question: Programming C++ Exercise 5.2.1. Optimize the prime-number function by calculating the square root of n only once during each function call. Declare a local variable

Programming C++

Exercise 5.2.1. Optimize the prime-number function by calculating the square root of n only once during each function call. Declare a local variable sqrt_of_n of type double. (Hint: A variable is local if it is declared inside the function.) Then use this variable in the loop condition.

Exercise 5.2.2. Rewrite main so that it tests all the numbers from 2 to 20 and prints out the results, each on a separate line. (Hint: Use a for loop, with i running from 2 to 20.)

Exercise 5.2.3. Write a program that finds the first prime number greater than 1 billion (1,000,000,000).

Exercise 5.2.4. Write a program that lets the user enter any number n and then finds the first prime number larger than n.

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!