我想找到2D数组中包含相同数字序列的列和行的索引。 例如
{2, 3, 2, 6}
{3, 6, 3, 10}
{7, 4, 2, 12}
{6, 8, 6, 4}
在此示例中,程序必须返回行索引0和列索引2 我用C语言编写了一个程序,但是没有用
# include <stdio.h>
int main(){
char tab[3][3];
int simiLgn, simiClm;
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("Tableau[%d][%d]=", i, j);
scanf("%d", &tab[i][j]);
}
}
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
printf("%d \t", tab[i][j]);
}
printf("\n");
}
int fix_lgn = 0;
int fix_col = 0;
while (fix_lgn<3){
while (fix_col<3){
for (int i=0, j=0; i<3, j<3 ; i++, j++){
if(tab[fix_lgn][j] == tab[i][fix_col]){
simiLgn = fix_lgn;
simiClm = fix_col;
}
else{
simiLgn = -1;
simiClm = -1;
}
}
fix_col++;
}
fix_col = 0;
fix_lgn++;
}
printf("ligne index: %d\n", simiLgn);
printf("colonne index: %d\n", simiClm);
return 0;
}
谢谢