#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; }