Answer to Question #236204 in C++ for MENSAH PAUL OSEI

Question #236204
Write a C++ program to determine prime number within a certain range( choose your own range )
1
Expert's answer
2021-09-12T04:58:44-0400


#include <iostream>


using namespace std;
void prime_numbers(int start, int stop)
{
    int f;
    for (int i = start; i <= stop; i++) {
        if (i == 1 || i == 0)
            continue;
        f = 1;
        for (int j = 2; j <= i / 2; ++j) {
            if (i % j == 0) {
                f = 0;
                break;
            }
        }
        if (f == 1)
            cout << i << " ";
    }
}
int main()
{
    int start;
    int stop;
    cout<<"\nEnter the start number: ";
    cin>>start;
    cout<<"\nEnter the stop number: ";
    cin>>stop;
    cout<<"\nThe prime numbers between "<<start<<" and "<<stop<<" are: ";
    prime_numbers(start,stop);
 
    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