Answer to Question #242939 in C++ for Frida

Question #242939

How can i store a funktion display that test a prime, next prime, previous prime display prime, and exit. Then add function call to display_menu in main function.


1
Expert's answer
2021-09-28T00:49:30-0400
#include <iostream>
using namespace std;


int check_prime(int num) {
    int i, f = 1;
    for (i = 2; i <= num / 2; ++i) {
        if (num % i == 0) {
            f = 0;
            break;
        }
    }
    return f;
}
int main() {
    int num1, num2, i, f;
    cout<<"\nEnter two integers: ";
    cin>>num1>>num2;
    cout<<"\nPrime numbers between %d and %d are: "<< num1<<num2;
    for (i = num1 + 1; i < num2; ++i) {
        f = check_prime(i);


        if (f == 1)
            cout<<i<<" ";
    }
    return 0;
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS