C++ Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows:
In C++
Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows:
A = 12345
B = A + 5000
Note: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29.
Rules:
-
You should first create a boolean function called isPrime and use that function in your program. This function should take in any int and return true if the number is prime, otherwise, return a false. In the main body of your program, you should create a loop from A to B (inclusive) and use isPrime function to determine if the loop number should be counted or not.
-
Your program SHOULD NOT PRINT the individual prime numbers. You can print them for your own testing purpose, but in the final submission, comment out such print statements.
-
Your program SHOULD ONLY PRINT the answer -- which is a number.
-
Do not print extra characters in your answer (E.g. "answer=123" instead of 123)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images