What is the output of the following present is estimate incl
Solution
OutPut:
for(int i=0;i<HEIGHT;i++){ // This loop go through Row wise
sum=0;
for(int j=0; j<WIDTH;j++)// This loop go through column wise
{
sum= sum +myArray[i][j];// In first loop i=0; and j changes value by second loop so it will j=0,1,2
myArray[i=0][j=0]=1,myArray[i=0][j=1]=1,myArray[i=0][j=0]=1,Ans Sum become sum= 3, similary for i=1,and j=0,1,2, sum become 6 and i=2 and j=0,1,2 sum become 9
}
}
so output uper nested loop:
3 6 9
for(int j=0; j<WIDTH;j ++){
sum=0;
for(int i=0;i<HEIGHT;i++){
sum= sum+ myArray[i][j]; // in outer loop time of loop j=0; inner loop takes values i=0,1,2 and myArray takes value myArray[i=0][j=0]=1, myArray[i=1][j=0]=2, myArray[i=2[[j=0]=3 and sum become 6
and again for outer loop take j=1, inner loop i=0,1,2 and myArray[0][1]=1,myArray[1][1]=2,myArray[2][1]=3, and sum=6,
and similary for j=2, i =0,1,2 and myArray[0][2]=1;myArray[1][2]=2;myArray[2][2]=3; and sum= 6
}
}
output by lower nested loop:
6 6 6
OverAll Output:
3 6 9
6 6 6
