1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
/* This program uses multidimensional arrays to find the largest
* number compared to their neighbors. I call this program ne.c */
#include <stdio.h> /* librarys */
#include "genlib.h"
#define size 5 /* constants */
void displayMatrix(int ne [size][size]);
int main()
{
/* the ne values you may change them if you wish */
int ne[size][size]=
{
{1,0,1,0,1}, /* if you are going to change the values please change the values on the inside not the outside */
{0,9,5,2,0},
{1,12,8,3,1},
{0,4,7,12,0},
{1,0,1,0,1}
};
displayMatrix(ne);
return 0;
}
void displayMatrix(int ne [size][size])
{
int i, j, m, n;
m = size;
n = size;
for (i=m-1;i<=m+1;i++)
{
for (j=n-1;j<=n+1;j++)
{
if (ne[i, j] > ne[m, n])
{
printf("%d in location (%d, %d)\n", ne[i, j], i, j);
}
}
}
getchar();
}
|