Monday, July 27, 2009

How to set this up in C programming using arrays?

int main(void)


{int table [6][6];


for (int row = 0; row%26lt;6; row++)


for (int column =0; column %26lt;6; column++)


if (row == column)


table [row][column] =0;


else if (row%26lt;column)


table [row][column] = -1;


else


table [row][column] = +1;





for (int row=0; row%26lt;6; row++)


{


for (int column =0; column %26lt;6; column++)


printf("%3d", table[row][column]);


printf("\n");


}


return 0;


}


this is what i have so far.....


0 1 1 1 1 1


-1 0 1 1 1 1


-1 -1 0 1 1 1


-1 -1 -1 0 1 1


-1 -1 -1 -1 0 1


-1 -1 -1 -1 -1 0








except the zeros have to be in the opposite diagonal...


1 1 1 1 1 0


1 1 1 1 0 -1


1 1 1 0 -1 -1


1 1 0 -1 -1 -1


1 0 -1 -1 -1 -1


0 -1 -1 -1 -1 -1





im truly conused plz help...

How to set this up in C programming using arrays?
Try changing your if statement to the following:





if ( (row + column) == 5 )


table [row][column] =0;


else if ( (row + column) %26lt; 5 ) //edited!


table [row][column] = 1;


else


table [row][column] = -1;
Reply:Change the way you are checking cell position.





Instead of row==column, use int(row+column)=5


in the if statement.





That will check the opposite diagonal.





0,5


1,4


2,3


3,2


4,1


5,0


No comments:

Post a Comment