i have a problem with a program which gets a matrix[3][3] (with values 1-20.) i want to print the index of cells whose surrounding cells all have lower values. in a matrix
0 0 0
0 1 0
0 0 0
it supposed to print only [1][1].
can someone look at my check_mat function an tell me how to repair it? thanks in advance.
#include <stdio.h>
#define N 3
#define M 3
int IsInside (int i, int r);
int GetNum ();
void get_mat (int mat[N][N]);
void print_mat (int mat[N][N]);
int sum_mat (int mat[N][N], int i, int j);
int check_mat (int mat[N][M], int i, int j);
void main()
{
int mat[N][N];
int i,j;
printf("%Please, insert %d nums, between 1-10\n", N*N);
get_mat(mat);
print_mat(mat);
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(check_mat,i,j)
printf("[%d][%d]\n",i,j);
}
}
//print_mat(mat);
}
int IsInside (int r, int c) //checks if the rows/colums are valid
{
if(r<0 || r>N || c<0 || c>N)
return 0;
return 1;
}
int GetNum ()
{
int num;
int check = 0;
do
{
if (check)
printf("error! between 1-10. try again");
scanf("%d", &num);
check++;
} while (num<0||num>10);
return num;
}
void print_mat (int mat[N][N])
{
int r, c;
for (r = 0; r < N; r++)
{
for (c = 0; c < N; c++)
{
printf("%3d", mat[r][c]);
}
printf("\n");
}
printf("\n\n");
}
void get_mat (int mat[N][N])
{
int r,c;
for(r=0;r<N;r++)
for(c=0;c<N;c++)
mat[r][c] = GetNum();
}
int check_mat (int mat[N][M], int i, int j)
{
int r,c;
int flag = 1;
for(r=i-1; r<i+1 ; r++)
{
for(c=j-1; c<j+1 ; j++)
if(mat[i][j]>mat[r][c]&&IsInside(r,c))
return 1;
return 0;
}
}