Advertisement
Guest User

Summation of Prime

a guest
Feb 27th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, sum=0;
  7. bool prime;
  8. cout<<"Enter an integer: ";
  9. cin>>n;
  10. for (int i=2; i<=n; i++){
  11. prime=true;
  12. for (int j=2; j<i; j++){
  13. if (i%j==0){
  14. prime=false;
  15. break;
  16. }
  17. }
  18. if (prime){
  19. sum+=i;
  20. }
  21. }
  22. cout<<"The sum is: "<<sum;
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement