C++ program to find prime numbers in a given range




cpp tutorials
cpp tutorials

Here we will learn how to write a program to find the prime numbers in a given range.

WRITE A C++ PROGRAM TO PRINT ALL THE PRIME NUMBERS WITH IN THE GIVEN RANGE

#include<iostream>
#include<iomanip>
using namespace std;

int main(){
    int num,i,count,n;
    cout << "Enter max range: ";
    cin >> n;
    for(num = 1;num<=n;num++){
         count = 0;
         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
       
         if(count==0 && num!= 1)
              cout << num << setw(3);
    }
 system("pause");
   return 0;
}

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*