#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int search_target(int arr[], int target, int ROW, int COLUMN)
{
int row = 0;
int column = COLUMN - 1;
if (arr != NULL && ROW > 0 && COLUMN > 0)
{
while (row < ROW && column >= 0)
{
if (arr[row * COLUMN + column] == target)
{
return 1;
}
else if (arr[row * COLUMN + column] < target)
{
++row;
}
else if (arr[row * COLUMN + column] > target)
{
--column;
}
}
return 0;
}
return 0;
}
int main()
{
int arr[][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int ret = search_target(arr, 7, 3, 3);
if (ret == 1)
{
printf("exist\n");
}
else
{
printf("not exist\n");
}
system("pause");
return 0;
}
C语言:【面试题】在二维数组中,每行每列都按照递增的顺序排序,判断数组中是否包含一个数。
原文:http://10740184.blog.51cto.com/10730184/1709969