int sum = 0;
int product = 1;
for ( int i = 1; i <= 100; i++ )
{
if ( i & 1 ) product *= i;
else sum += i;
}
std::cout << "sum = " << sum <, std:;endl;
std::cout << "product = " << product << std::endl;
In fact this product is similar to factorial.The maximum number the factorial of which can be stored in an object of type int provided that the type int occupies 4 bytes is equal to 12.:)
i think i misunderstood you or you misunderstood me XD
anyways what am i expecting in the output will be like this
2
4
.
.
.
98
100
the total sum is XX
1
3
.
.
.
96
99
the total product is XX
am expecting to see this in console as an output..
i do have "this" idea on how am i will be able to put the numbers on output but i am wondering if how am i be able to do the arithmetic operation without writing sum = 2+4+6+....+98+100... do you guyz get my point? XD
You don't need a computer for a lot of things, it just sometimes saves a lot of time, plus even in cases like this, means you don't have to derive formulas.
I think i understand what you want and it is not very hard but you cod not communicate it correctly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int sum = 0;
int product = 1;
int i;
for ( i = 1; i <= 100; i++ )
{
if ( i & 1 ) product *= i;
else sum += i;
}
for ( i=2; i<100; i=i+2)
{
cout<<i<<"+";
};
cout<<i<<"="<<sum<<endl;
for ( i=1; i<99; i=i+2)
{
cout<<i<<"*";
};
cout<<i<<"="<<product<<endl;
I hope this is the code you want. I am sorry about the grammar , my keyboard is almost broken.