for loop - Code of neighbor finding program in C -


the instructions write program uses 2 - dimensional array find elements larger neighbors.

for example if input is:  1   2   11 13  5   6 7   6   9  output be: 11, 13, 9 

for reason though displays no numbers @ all. correct code.

here code:

#include <stdio.h>                                           #include "genlib.h" #include "simpio.h"  #define n 3                                                   bool neighbourcheck(int array[n+2][n+2], int i, int j);      void getarray(int array[n+2][n+2]);  main()                                                   {       int array[n+2][n+2], i, j;        printf("this program ask enter 9 integers of aray.\n");       getarray(array);       (i=1; i<n+1; i++)       {                 for(j=1; j<n+1; j++)                 {                          if(neighbourcheck(array, i, j)==true)                          {                                         printf("%d\t", array[i][j]);                                      }                         }       }       getchar(); }  void getarray(int array[n+2][n+2]) {       int i, j;        for(j=0;j<=n+1;j++)       {                 i=0;                 array[i][j]=-1;                 i=4;                 array[i][j]=-1;                          }       for(i=1;i<n+1;i++)       {                 j=0;                 array[i][j]=-1;                 j=4;                 array[i][j]=-1;                        }       for(i=1;i<n+1;i++)       {                 for(j=1;j<4;j++)                 {                                 printf("\nenter positive integer: ");                                 array[i][j]=getinteger();                                 }       }    }  bool neighbourcheck(int array[n+2][n+2], int i, int j)                       {      int l, m;       for(l=i-1; l<i+1; l++)      {                 for(m=j-1; m<j-1; m++)                 {                          if(array[l][m]>=array[i][j])                          {                                         return(false);                                                      }                          return(true);                 }      } }   

thank :d

you have change part

for(l=i-1; l<i+1; l++) {         for(m=j-1; m<j-1; m++) 

into:

for(l=i-1;l<=i+1;l++) {         for(m=j-1;m<=j-1;m++) 

cheers!


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -