0
Why answer is " sum= 21"
#include <iostream> using namespace std; int main() { int array [7],sum=0; for(int i=0;i<7;i++) { array [i] = i; sum +=array[i]; } cout << "sum =" << sum; }
6 ответов
+ 4
To explain this, look at the 'for' loop.
In short, it means that 'i' , as well as number of arrays will become 0, then 1, then 2, then 3... and it stops once 'i' becomes 7.
And you can see this 'sum += array[i];' , to simplify it, it just means this :
sum = sum + i;
Hence, if you go through the loop until 'i' becomes 7, sum will become " 0+1+2+3+4+5+6" which is 21.
+ 3
sum initially is 0.
in the 'for loop' we add each i value to sum until i=6 (i<7).
that makes
0+1+2+....+6 = which is nothing but 21.
0
can any body explain the code
0
i can
0
please tell me why the answer sum = 21
0
thank you to explain