Project Euler Problem 1


/ Published in: C++
Save to your folder(s)

Sorted by problem ID.


Copy this code and paste it in your HTML
  1. /*
  2. Alexander DeTrano
  3. 2/1/2010
  4. Project Euler - Problem 1
  5.  
  6. Add all the natural numbers below one thousand that are multiples of 3 or 5.
  7. */
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. int x =0; int z=0;
  16. for (int i=0;i<1000;i++){
  17. if ( i%3 == 0||i%5 == 0){
  18. z=i + z;
  19. }
  20. }
  21. cout<<"z= " << z <<"\n";
  22.  
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.