Find prime number in c++




How to find prime number in c++


#include<iostream>
#include<iomanip>

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);
    }
 
   return 0;
}


Programs of c++


Post a Comment