Hi guys, I just had a simple question, one of my homework assignments was to write a multidimensional array that displays the elements of that array that are larger than all their neighbors.
The problem is, when I use a function I made myself to attempt to give a visual of the array, I get the number -858993460 in place of what should be there. The rest of the program however works fine. I'm kinda stumed here, any help is appreciated. Here's the code I'm using:
Again, thanks for any helpCode:/* *File: neighbors.c *The program creates a multidimensional array, and then displays the elements of that *array that are larger than all their neighbors. */ #include "stdafx.h" #include <stdio.h> #include "genlib.h" #include "simpio.h" #define size 5 void getArray(int ne[][size]); bool check_neighbors(int ne[][size],int i,int j); void displayArray(int ne[][size]); main() { int ne[size][size],i,j; getArray(ne); printf("Your array is:\n"); displayArray(ne); for(i=1;i<size-1;i++) { for (j=1;j<size-1;j++) { if (check_neighbors(ne,i,j)==true) printf("%d in location (%d,%d)\n",ne[i][j],i-1,j-1); } } } void getArray(int ne[][size]) { int i,j; for(i=1;i<size-1;i++) { for (j=1;j<size-1;j++) { printf("\nEnter next integer: "); ne[i][j]=GetInteger(); } } } void displayArray(int ne[][size]) { int i,j; for (i=1;i<size-1;i++); { for (j=1;j<=size-1;j++) { printf("%4d",(ne[i][j])); } printf("\n"); } } bool check_neighbors(int ne[][size],int i,int j) { if ((ne[i+1][j+1]<=ne[i][j])&&(ne[i-1][j-1]<=ne[i][j])&&(ne[i+1][j]<=ne[i][j])&&(ne[i][j+1]<=ne[i][j])&&(ne[i-1][j]<=ne[i][j])&&(ne[i][j-1]<=ne[i][j])&&(ne[i+1][j-1]<=ne[i][j])&&(ne[i-1][j+1]<=ne[i][j])) { return (true); } else return(false); }



LinkBack URL
About LinkBacks


