Write a program that prints the count of all prime numbers between A and B (inclusive),...

90.2K

Verified Solution

Question

Programming

Write a program that prints the count of all prime numbersbetween A and B (inclusive), where A and B are defined asfollows:

A = The 5 digit unique number you had picked at the beginning ofthe semester

B = A + 5000

Just a recap on prime numbers: A prime number is any number,greater or equal to 2, that is divisible ONLY by 1 and itself. Hereare the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and29.

Rules:

  1. You should first create a boolean function called isPrime anduse that function in your program. This function should take in anyint and return true if the number is prime, otherwise, return afalse. In the main body of your program, you should create a loopfrom A to B (inclusive) and use isPrime function to determine ifthe loop number should be counted or not.

  2. Your program SHOULD NOT PRINT the individual prime numbers. Youcan print them for your own testing purpose, but in the finalsubmission, comment out such print statements.

  3. Your program SHOULD ONLY PRINT the answer -- which is anumber.

  4. Do not print extra characters in your answer (E.g. \"answer=123\"instead of 123)

the values for me:

A = 5000;

B = A+5000;

sample code to get started--->>>>>>>>>>

#includeusing namespace std;bool isDivisibleBy(int num, int divisor) {    // function returns true if num is divisible by divisor    if(num % divisor == 0) {        return true;    } else {        return false;    }}bool isodd(int num) {    // function returns true if num is odd    if( isDivisibleBy(num,2) ) {        return false;    } else {        return true;    }}int main() {    const int A = 1;    const int B = 100;    const int N = 17;        int count = 0;        // count of the numbers between A and B that are odd and divisible by N        for(int i=A; i<=B; i++) {        if( isDivisibleBy(i,N) && isodd(i) ) {            count++;        }    }        // just print the answer and nothing else...    cout << count << endl;    return 0;}

Answer & Explanation Solved by verified expert
3.6 Ratings (305 Votes)
There are multiple ways to find if a number is a prime number or    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students