Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- bool prime (int n)
- {
- double a = sqrt((double)n);
- if (n==1) return true;
- for (int i=2; i < floor(a)+1; i++)
- if (n%i==0) return false;
- return true;
- }
- int main (void)
- {
- int a,b;
- cout << "Enter a & b" << endl;
- cin >> a >> b;
- int k=0;
- for (int i=a; i<=b; i++)
- if (prime(i)==false)
- k+=i;
- cout << "Result = " << k << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment