Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sum1() {
- int s = 0;
- int buf[1000] = {0};
- for(int i=0; i<1000; i+=3)
- if (buf[i] == 0) { buf[i] = 1; s += i; }
- for(int j=0; j<1000; j+=5)
- if (buf[j] == 0) { buf[j] = 1; s += j; }
- return s;
- }
- int sum2() {
- int s = 0;
- for(int i=0; i<1000; i++)
- if (((i % 3) == 0) || ((i % 5) == 0)) s+=i;
- return s;
- }
- int main()
- {
- cout << sum1() << endl << sum2() << endl;
- }
Add Comment
Please, Sign In to add comment