Print prime number with geivn reange

 Write a program to give the number of prime within the range in the c++ program.



#include <iostream>

using namespace std;


bool isprimeNum(int n){

    if(n<2){

        return false;

    }

    for(int i=2; i<n; i++){

        if(n%i==0){

            return false;

        }

    }

    return true;

}


int main() {

    int n1, n2;

    cout<<"Enter the first number "<<endl;

    cin>>n1;

    cout<<"Enter the second number "<<endl;

    cin>>n2;

    cout<<"The prime numbers "<<endl;

    for(int i=n1; i<=n2; i++){

        if(isprimeNum(i)){

            cout<<i<<" ";

        }

    }

    

    return 0;

}


please do comments and share with your friends 

Post a Comment

0 Comments