+ 1
Explain how this worksâ
#include <iostream> using namespace std; int main() { int arr3[2][3][3]={ { {5,6,2},{3,4,4},{2,7,5}}, { {5,7,6},{7,8,1},{1,2,6}} }; int i=0,j; for(j=0;j<2;j++){ i += arr3[j][j][j]; }cout << i; return 0; } why 'i' value is 13? ........i know!!
4 Answers
+ 11
arr3[0][0][0] and arr3[1][1][1] was added to i, i is printed. (5 + 8) = 13.
+ 2
#include <iostream>
using namespace std;
int main() {
int arr3[2][3][3]={
{ {5,6,2},{3,4,4},{2,7,5}},
{ {5,7,6},{7,8,1},{1,2,6}}
};
int i=0,j;
for(j=0;j<2;j++){
i += arr3[j][j][j];
cout << "arr3[" << j << "][" << j << "][" << j << "]=" << arr3[j][j][j] << endl;
}cout << "summa ="<< i;
return 0;
}
//why you get 13 as the answer?
+ 1
@Konstantin
i think you meant "sum" not "summa"
+ 1
Yes. )