#include <stdio.h>
int Find(int* matrix, int rows, int columns, int number)
{
if (matrix != NULL && rows > 0 && columns > 0)
{
int row = 0;
int column = columns - 1;
while (row < rows && column >= 0)
{
if (matrix[row * columns + column] == number)
{
return 0;
}
else if (matrix[row * columns + column] > number)
--column;
else
++row;
}
}
return -1;
}
void Test1()
{
int matrix[][4] = { {1, 2, 8, 9}, {2, 4, 9, 12}, {4, 7, 10, 13}, {6, 8, 11, 15} };
int a = Find(matrix, 4, 4, 7);
if (a == 0)
{
printf("二维数组中有此数\n");
}
else {
printf("二维数组中没有此数\n");
}
}
int main(int argc, char* argv[])
{
Test1();
return 0;
}
08-09
646
04-26
07-20
811
12-21
1万+