Code for sum of prime numbers in c++





Code for sum of prime numbers in c++

#include<iostream>

int main(){

    int num,i,count,sum=0;

    for(num = 1;num<=100;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;


2 comments:

Unknown said...
This comment has been removed by the author.
ASHIMA ARORA said...
This comment has been removed by the author.