#include <stdio.h>
int findnum(int* (*arr)[4], int r, int c, int k)
{
// 先找出右上角的值
int i = 0;
int j = c - 1;
while (i <= r && j >= 0)
{
if (k > arr[i][j])
{
i++;
}
else if (k < arr[i][j])
{
j--;
}
else
{
return 1;
}
}
return 0;
}
int main()
{
int arr[4][4] = { 1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7 };
int k = 6;
int ret = findnum(arr, 4, 4, k);
if (ret == 1)
{
printf("存在!");
}
else
{
printf("不存在!");
}
return 0;
}
【C语言】杨氏矩阵
我叫小白菜2023-10-15 13:18