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.
#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;
}
Comments
Leave a comment