Seal_of_approval

p37e3

Feb 10th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool prime (int n)
  6. {
  7. double a = sqrt((double)n);
  8. if (n==1) return true;
  9.  
  10. for (int i=2; i < floor(a)+1; i++)
  11. if (n%i==0) return false;
  12.  
  13. return true;
  14. }
  15.  
  16. int main (void)
  17. {
  18. int a,b;
  19. cout << "Enter a & b" << endl;
  20. cin >> a >> b;
  21.  
  22. int k=0;
  23. for (int i=a; i<=b; i++)
  24. if (prime(i)==false)
  25. k+=i;
  26. cout << "Result = " << k << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment