![](https://file.jishuzhan.net/article/1713424158454452226/bfb6fb13c96a25a94a32acc01697364f.webp)
![](https://file.jishuzhan.net/article/1713424158454452226/9e33d96e34148614546e92e4a6bd87be.webp)
#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;
}