#include <iostream>
usingnamespace std;
int main()
{
float sum = 0.0;
for (int i = 1; i <= 1000; i++)
{
if (((i % 3) == 0) && ((!i % 4) == 0) && ((!i % 5) == 0))
{
sum = sum + i;
}
}
cout << "The sum of numbers up to a thousand and only divisible by 3:\t" << sum << endl;
system("pause");
}
(!i % 4) == 0
But which is evaluated first, the 'logical not' or the 'modulo'? C++ has clear operator precedence rules, and the answer is 'logical not'. Therefore, we can add more parenthesis without changing the expression: ( (!i) % 4 ) == 0
But what is NOT i? When is it divisible by 4?