//杨氏矩阵
//有一个数字矩阵,矩阵的每行从左到右的递增的,矩阵从上到下是递增的
//请编写一个程序,在这样的矩阵中查找某个数字是否存在
// 1 2 3
// 4 5 6
// 7 8 9
#include<stdio.h>
int main()
{int a[3][3] = { 0 };int i = 0, j = 0;int m = 0;scanf("%d", &m);for (i = 0; i < 3; i++){for (j = 0; j < 3; j++){if (i == 0 && j == 0){a[i][j] = m;}else{m ++;a[i][j] = m ;}}}for (i = 0; i < 3; i++){for (j = 0; j < 3; j++){printf("%d ", a[i][j]);}printf("\n");}int n = 0;printf("请输入需要查找的数字:");scanf("%d", &n);for (i = 0; i < 3; i++){for (j = 0; j < 3; j++){if (a[i][j] == n){printf("找到了a[%d][%d]\n", i, j);}}}return 0;
}
输出结果: