#include "stdio.h"
int find(int data[4][4], int rows, int columns, int number);
main() {
int data[4][4] = {
{1,2,8,9},
{2,4,9,12},
{4,7,10,13 },
{6,8,11,15}
};
int result = find(data, 4, 4, 7);
if(1 == result)
printf("查询存在");
else
printf("不存在");
getch();
}
/*
row:行,columns:列
找到返回1,否则返回0
*/
int find(int data[4][4], int rows, int columns, int number) {
int column = 3;
int row = 0;
if(rows==0 || 0 == columns) {
return 0;
}
while(column < columns && row >= 0) {
if(data[row][column] == number) {
return 1;
} else if(data[row][column] > number) {
column--;
} else {
row++;
}
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考