Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,288 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,242 people online right now. Registration is fast and FREE... Join Now!




2d array cell comparison

 
Reply to this topicStart new topic

2d array cell comparison, heh, stupid me

Re@p3rM4n
post 2 Apr, 2008 - 04:50 PM
Post #1


New D.I.C Head

*
Joined: 5 Feb, 2008
Posts: 41


My Contributions


say you have a 2d array and want to see which cells' values are larger than that of their surrounding cells
the following is a failed stab at it
i may just need major help on this one
CODE

#include <iostream>
#include <math.h>
#include <stdio.h>
#define minNist -32766
/*input is fine, problem in comparison/looping poss. both*/
bool all_true[8];
bool  GEqualToNeighbours(int matrix[5][5],int m, int n)
{
     int i=0,j=0,p=0;
    
     for(i=m-1;i<=m+1;i++)
     {
               for(j=n-1;j<=n+1;j++)
               {
                        if(matrix[m][n]>=matrix[i][j]){  all_true[p]=true; p++;}
                        else{all_true[p]=false; p++;}
               }
     }
     return true;
}
                        
void solve(int matrix[5][5])
{
     int m=0,n=0;
    
     for(m=0;m<4;m++)
     {
               for(n=0;n<4;n++)
               {
                      GEqualToNeighbours(matrix,m,n);
                      if(all_true[0]==true && all_true[1]==true && all_true[2]==true && all_true[3]==true && all_true[4]==true && all_true[5]==true && all_true[6]==true && all_true[7]==true) printf("(%i,%i)\n",m-1,n-1);
               }
     }
}

int main(int argc, char *argv[])
    {
             int temp1=0, temp2=0, temp3=0, matrix[5][5];
             bool a_true[8];
             printf("Please enter 1st row like this: 1,2,3\n");
             scanf("%i,%i,%i",&temp1,&temp2,&temp3);
             matrix[1][1]=temp1;
             matrix[1][2]=temp2;
             matrix[1][3]=temp3;
            
             printf("Please enter 2nd row like this: 1,2,3\n");
             scanf("%i,%i,%i",&temp1,&temp2,&temp3);
            
             matrix[2][1]=temp1;
             matrix[2][2]=temp2;
             matrix[2][3]=temp3;
            
             printf("Please enter 3rd row like this: 1,2,3\n");
             scanf("%i,%i,%i",&temp1,&temp2,&temp3);
            
             matrix[3][1]=temp1;
             matrix[3][2]=temp2;
             matrix[3][3]=temp3;
            
             matrix[0][0]=minNist;
             matrix[0][1]=minNist;
             matrix[0][2]=minNist;
             matrix[0][3]=minNist;
             matrix[0][4]=minNist;
            
             matrix[4][0]=minNist;
             matrix[4][1]=minNist;
             matrix[4][2]=minNist;
             matrix[4][3]=minNist;
             matrix[4][4]=minNist;
            
             matrix[0][0]=minNist;
             matrix[1][0]=minNist;
             matrix[2][0]=minNist;
             matrix[3][0]=minNist;
             matrix[4][0]=minNist;
            
             matrix[0][4]=minNist;
             matrix[1][4]=minNist;
             matrix[2][4]=minNist;
             matrix[3][4]=minNist;
             matrix[4][4]=minNist;
            
             //printf("%i\t%i\t%i\t%i\t%i",matrix[0][0],matrix[0][1],matrix[0][2],matrix[0][3],matrix[0][4]);
             //printf("%i\t%i\t%i\t%i\t%i",matrix[1][0],matrix[1][1],matrix[1][2],matrix[1][3],matrix[1][4]);
           //printf("%i\t%i\t%i\t%i\t%i",matrix[2][0],matrix[2][1],matrix[2][2],matrix[2][3],matrix[2][4]);
            //printf("%i\t%i\t%i\t%i\t%i",matrix[3][0],matrix[3][1],matrix[3][2],matrix[3][3],matrix[3][4]);
            //printf("%i\t%i\t%i\t%i\t%i",matrix[4][0],matrix[4][1],matrix[4][2],matrix[4][3],matrix[4][4]);
            
             solve(matrix);
             system("PAUSE");
    }            
            


i decided to pad the 3x3 array with quite small values , so it became a 5x5 array, only 3x3 of which matter
help, please?
-R

This post has been edited by Re@p3rM4n: 2 Apr, 2008 - 04:58 PM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 01:10AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month