题目描述
给定一个n * n矩阵a,满足条件:
①对于所有1≤i≤n,ai,1 = a1,i = 1
②在①条件之外的位置,每个位置的值均等于它上面的值与左面的值的和。
请你找到矩阵中最大的数字是多少。
Given a n*n matrix A, which satisfies the conditions:
①for all the position of ai,if 1≤i≤n,ai,1 = a1,i = 1
②beyond the condition ①, each value of the position is equal to the sum of the value of above posotion and the value of left position.
Please find out the largest number in the matrix.
输入
一个整数n,代表矩阵规模。(1≤n≤10)
an integer n, which represents the scale of the matrix.(1≤n≤10)
输出
一个整数ans,表示矩阵中的最大数字。
an integer ans, which represents the largest number in the matrix.
样例输入
5
样例输出
70
提示
来源
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, a[10][10], i, j;
while(scanf("%d",&n)!= EOF){
for (i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if (i == 1 || j == 1)
a[i][j] = 1;
else
a[i][j] = a[i-1][j] + a[i][j-1];
}
}
printf("%d\n", a[n][n]);
}
return 0;
}
#include <stdlib.h>
int main() {
int n, a[10][10], i, j;
while(scanf("%d",&n)!= EOF){
for (i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if (i == 1 || j == 1)
a[i][j] = 1;
else
a[i][j] = a[i-1][j] + a[i][j-1];
}
}
printf("%d\n", a[n][n]);
}
return 0;
}