1. ## Diagonals

supose theres an array SIZE X SIZE i getin coordinate a,b from user and i want to check all the diagonals including the cell a,b in the array .

those for loops alright ?

1.

for(i=a-1, j=b+1; (0<=i)||(j<SIZE-b); i--,j++)

2.

for(i=a+1,j=b-1; (i<SIZE-b)||(0<=j); i++,j--)

3.

for(i=a-1,j=b-1; ((0<=i)||(0<=j)); i--, j--)

4.

for(i=a+1,j=b+1; ((i<SIZE)&&(j<SIZE)); i++, j++)

should i change || to && somewhere ?

TNX ...........

P.S : of course without check the cell a,b .

2. Originally Posted by the_contractor
those for loops alright ?
Probably you will need to compile them as a program and run that on a computer :P

P.S : of course without check the cell a,b .
Check??!? How??

3. ## here it is......

Code:
```#include <stdio.h>
#define SIZE 8
void print(int board[SIZE][SIZE])
{
int i,j;
for(i=0; i<SIZE; i++)
{
for(j=0; j<SIZE; j++)
printf("%2d",board[i][j]);
printf("\n");
}
printf("\n\n\n");
}

void main()
{
int arr[SIZE][SIZE]={0}, i,j,a,b;
printf("Enter Coordinate (a,b): ");
scanf("%d,%d",&a,&b);
printf("Enter Value arr[%d][%d]: ",a,b);
scanf("%d",&arr[a][b]);

for(i=a-1, j=b+1; (0<=i)||(j<SIZE-b); i--,j++)
{
arr[i][j]=8;
getchar();
print(arr);
}
for(i=a+1,j=b-1; (i<SIZE-b)||(0<=j); i++,j--)
{
arr[i][j]=8;
getchar();
print(arr);
}
for(i=a-1,j=b-1; ((0<=i)||(0<=j)); i--, j--)
{
arr[i][j]=8;
getchar();
print(arr);
}
for(i=a+1,j=b+1; ((i<SIZE)&&(j<SIZE)); i++, j++)
{
arr[i][j]=8;
getchar();
print(arr);
}

}```
ive get some problems i dont know why .

4. Originally Posted by MK27
Probably you will need to compile them as a program and run that on a computer :P

Check??!? How??

mean to skip the cell a,b .

5. Originally Posted by the_contractor
ive get some problems i dont know why .
I do: you are not communicating effectively. You need to describe the problems.

This is not just to help make things easier for someone who may want to help you (but that is probably a good enough reason anyway) -- describing the problem will also help you understand it, I promise.

80-90% of the questions I intend to ask on the forum never get posted, because as I am typing in the message box I think, well, the first thing someone is going to say is "Did you check ....?" so then I do that. Or else just finding the words makes it clearer and the answer comes along with that. Honestly.

6. I am guessing part of your problem stems from this:
STDIN pitfalls

7. well you can check the surrounding array elements for every point in a 2d array using three nested loops,

outerloop, y-axis, next loop, x-axis, inner loop to check surrounding points, runs 9 times, once for each point touching your a,b and including the a,b.
it tests, "is point y-1, x-1 my condition?, next loop, is y-1, x my condition?, next, is y-1, x+1 my condition?
etc etc

you need to watch out you are not searching into invalid array area though, you should have some kind of edge detection or trap for non valid array indexes.

80-90% of the questions I intend to ask on the forum never get posted, because as I am typing in the message box I think, well, the first thing someone is going to say is "Did you check ....?" so then I do that. Or else just finding the words makes it clearer and the answer comes along with that. Honestly.
thats so true...

8. This is a bad design to use while you're coding up the program and testing it. Give all the 64 squares a set value, so you don't have to spend time laboriously entering data with every test you run.

Then you should have 4 functions: rowCheck, colCheck, and diagCheck. row is very easy, column is more difficult, but just remember to increment by 8 (or whatever width you ultimately use for the board - more on that, later).

The diagonal check function is the most difficult, but just take it one direction at a time: i like to work clockwise from straight up, so my first diagonal would be the one toward 2 o'clock. With this diagonal, you'll be subtracting 7 columns and 1 row, with each trip through the loop.

What you have to watch out for with diagonals is "wrap around" onto the other side of the board. Always have your display function up and running, and use it to check your results, as you go.

I sometimes use a 10 X 10 board, because that lets me put an edge value, in all the squares surrounding the center 8 by 8 board. That can be used to stop wrap around really easily.

If you can put your problem into words, I can show you how to fix it. Just saying "it doesn't work or it has problems", doesn't work for me, because it doesn't tell me WHAT problems you're having.