-
2 dimensional array
I cannot see any reason this doesn't work. Here are the errors I get.
error C2059: syntax error : '['
error C2059: syntax error : '['
error C2146: syntax error : missing ')' before identifier 'sumrow5'
error C2059: syntax error : ')'
the first two errors brings me to the line of sumrow1.
insert
Code:
#include "stdafx.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
#define rows 5
#define cols 5
int val[rows][cols]={8,3,9,0,10,3,5,17,1,1,2,8,6,23,1,15,7,3,2,9,6,14,2,6,0};
int a, b, sumrow, sumrow1, sumrow2, sumrow3, sumrow4, sumrow5, sumcol, sumcol1, sumcol2, sumcol3, sumcol4, sumcol5;
printf("\ndisplay of elements\n");
{
for (a=0; a<rows; a++)
printf("\n");
for (b=0; b<cols; b++)
printf("%d\n", val[a][b]);
}
sumrow1= val[0][0]+val[0][1]+val[0][2]+val[0][3]+[0][4];
sumrow2= val[1][0]+val[1][1]+val[1][2]+val[1][3]+[1][4];
sumrow3=val[2][0]+val[2][1]+val[2][2]+val[2][3]+val[2][4];
sumrow4=val[3][0]+val[3][1]+val[3][2]+val[3][3]+val[3][4];
sumrow5=val[4][0]+val[4][1]+val[4][2]+val[4][3]+val[4][4];
sumcol1=val[0][0]+val[1][0]+val[2][0]+val[3][0]+val[4][0];
sumcol2=val[0][1]+val[1][1]+val[2][1]+val[3][1]+val[4][1];
sumcol3=val[0][2]+val[1][2]+val[2][2]+val[3][2]+val[4][2];
sumcol4=val[0][3]+val[1][3]+val[2][3]+val[3][3]+val[4][3];
sumcol5=val[0][4]+val[1][4]+val[2][4]+val[3][4]+val[4][4];
printf("the row totals are %d %d %d %d %d\n", sumrow1, sumrow2, sumrow3, sumrow4 sumrow5);
printf("the coloumn totals are %d %d %d %d %d", sumcol1, sumcol2, sumcol3, sumcol4, sumcol5);
return 0;
}
-
you are missin val in the last member
your sumrow and sumcol should be arrays as well
here is the proper way to initialize two-dimentional array
Code:
int val[rows][cols]={{8,3,9,0,10},{3,5,17,1,1},{2,8,6,23,1},{15,7,3,2,9},{6,14,2,6,0}};
-
thanks
thanks vart, that was the first time so far in using the board that someones advice lead me to fixing my program so it works. Usually I just end up with more questions or another dead end.