i tried to do this its not working..
Code:for(kndex=0;kndex<cols;kndex++){ for(index=0;index<rows;index++){ sumc[kndex]=sumc[kndex]+matrix[kndex][index]; } } for(index=0;index<cols;index++){ printf("%d",sumc[index]); }
i tried to do this its not working..
Code:for(kndex=0;kndex<cols;kndex++){ for(index=0;index<rows;index++){ sumc[kndex]=sumc[kndex]+matrix[kndex][index]; } } for(index=0;index<cols;index++){ printf("%d",sumc[index]); }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
if i get a 2d array like this
1 1 1
2 2 2
it needs
to put in the arr aray 3 3 3
(summing all the of the columns)
i tried this code
i cant see the error
cols is the number of column
rows is the number of rows
Code:for (index = 0; index < rows; index++) { for (kndex = 0; kndex < cols; kndex++) { arr[index]=arr[index]+matrix[kndex][index]; } } for (kndex = 0; kndex < cols; kndex++) { printf("%d ",arr[kndex]); }
Why don't you do as laserlight has already suggested (elsewhere), and post the smallest compilable bit of code that you can, rather than these little snippets without any context at all?
when my
matrix array is
1 1 1
2 2 2
it prints me
3 3 3 1
why??
Code:for (kndex = 0; kndex < cols; kndex++) { for (index = 0; index < rows; index++) { arr[kndex]=arr[kndex]+matrix[index][kndex]; } } for (kndex = 0; kndex < cols; kndex++) { printf("%d ",arr[kndex]); }
stupid error
solved it