This is wierd, everytime I do something I put in the answer it tells me I'm wrong. I'm doing the programs in C++. Can someone tell me where I'm wrong?
Problem 1: Find the sum of all the multiples of 3 or 5 below 1000.
int counter = 0;
for (int i = 0; i < 1001; i ++)
{
if (i % 3 == 0 || i % 5 == 0)
{
counter += i;
}
}
cout << counter << "\n";
system("PAUSE");
return 0;
Problem 2: Find the sum of all the even-valued terms in the sequence which do not exceed one million.
int first = 1, second = 2, total = 0, temp;
for (;;)
{
temp = first + second;
if (temp >= 1000000)
{
break;
}
if (temp % 2 == 0)
{
total += temp;
}
first = second;
second = temp;
}
cout << temp << "\n";
system("PAUSE");
return 0;
Problem 6: Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
int squareS = 0;
int sSquare = 0;
for (int i = 1; i < 1001; i++)
{
squareS += i;
sSquare += i * i;
}
squareS *= squareS;
cout << squareS - sSquare << "\n\n";
system("PAUSE");
return 0;