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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started