C ++ code of sum of prime in given range




C ++ code of sum of prime in given range

#include<iostream>
int main(){

    int num,i,count,min,max,sum=0;

    cout << "Enter min range: ";
    cin >> min;
    cout << "Enter max range: ";
    cin >> max;

    for(num = min;num<=max;num++){

         count = 0;

         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
       
         if(count==0 && num!= 1)
             sum = sum + num;
    }

   cout << "Sum of prime numbers is: " << sum;
 
   return 0;
}

C++ program to find all prime numbers in given max range


Post a Comment