View Code of Problem 27

#include<iostream>
#include<math.h>
using namespace std;
void swap(int &a,int &b)
{
    int t=a;
    a=b;
    b=t;
}
int isPrime(int x)
{
    int i;
    if(x==1||x==0)return 0;
    for( i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)return 0;
    }
    if(i>sqrt(x))return 1;

}
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a>b)
        swap(a,b);
        int sum=0;
         for(int i=a+1;i<b;i++)
         {
             if(isPrime(i)==1)
                sum+=i;
         }
         cout<<sum<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 27