查找某个数
#include<stdio.h>
#include<assert.h>
#include<windows.h>
int find_target(int arr[][5], int rows, int target)
{
assert(arr);
assert(rows > 0);
int i = 0;
int j = 4;
while (i < rows && j >= 0)
{
if (arr[i][j] == target)
{
return 1;
}
else if (arr[i][j]>target)
{
j--;
}
else
{
i++;
}
}
return 0;
}
int main()
{
int arr[5][5] = { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 },\
{ 11, 12, 13, 14, 15 }, { 16, 17, 18, 19, 20 }, { 21, 22, 23, 24, 25 } };
printf("%d\n", find_target(arr, 5, 16));
system("pause");
return 0;
}
杨氏矩阵
最新推荐文章于 2024-02-04 13:32:17 发布