At dreamincode.net/forums/ I found a thread regarding a list of sites that can help in learning C++, or programming at general. One of them is projecteuler.net. Interesting, as I have hard time since the first problem. I like solving problem especially when it is challenging. :)
/*
If we list all the natural number below 10 that are multiples of 3 or 5, we get 3,5,6, and 9.
The sum of these multiples is 23. find below 1000.
*/
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int number, sum, max=1000;
for (number=0,sum=0;number<max;number++)
{
if (((number%3)==0)||((number%5)==0))
sum+=number;
cout << number <<'+';
}
cout << endl;
cout <<"The sum of natural number below "<< max <<" is:" << sum;
getch();
}
No comments:
Post a Comment