# Find 2 matching pairs different values in a two dimension array C language

I am looking for some assistance with the isPair function. The function should tell me if there are two pairs in the 5 values. It is only robust enough to tell me if there is 1 pair.

I am trying to find if there are two matches of values 1-5 in the same columns in a 4x10 2D array.

• There are numbers valued 1-5 randomly placed in the 2d array and I need to know if two sets are in the same column.

• The remaining columns are rows are filled with the last 35 values, also randomly inserted throughout the rows and columns.

• In the following example, I have inserted some ‘dummy’ data to test my output. The code successfully tells me if I have 1 match, but not if I have two matches.

• This is hopefully clearer!

Pls note that this is not a search to find matching values in an array column - rather two see if there are two matches of the 1-5 values in the array.

Thx! Karen Stumped

#include <stdio.h>
#define FRUITS 4
#define NUMBERS 10

void isPair(unsigned int Go[NUMBERS]);
int main(void) {

unsigned int go[FRUITS][NUMBERS] = {0};

go[0][1] = 1;
go[1][1] = 2;
go[3][3] = 4;
go[3][4] = 5;

isPair(go);
}

void isPair(unsigned int Go[NUMBERS]) {
int a,b,x = 0;

size_t i,j, number, row0, row1, column;

for (i = 1; i <=5; ++i) {
for(j =1; j <=5 && j!=i; ++j) {
for (row0 = 0; row0 < FRUITS; ++row0) {
for (row1 = 0; row1 < FRUITS &&row1 != row0; ++row1) {
for (column = 0; column < NUMBERS; ++column) {
if ((Go[row0][column] ==i) && (Go[row1][column] ==j)) {
printf(“%s”, “A match!”);
}
}
}
}
}
}
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.