题解 | #杨辉三角#
杨辉三角
http://www.nowcoder.com/practice/e671c6a913d448318a49be87850adbcc
int C(int n, int m)
{
if (n == m || m == 0)
{
return 1;
}
else
{
return C(n - 1, m) + C(n - 1, m - 1);
}
}
#include<stdio.h>
int main()
{
int n = 0;
while (~scanf("%d", &n))
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
{
printf("%5d", C(i, j));
}
printf("\n");
}
}
return 0;
}
{
if (n == m || m == 0)
{
return 1;
}
else
{
return C(n - 1, m) + C(n - 1, m - 1);
}
}
#include<stdio.h>
int main()
{
int n = 0;
while (~scanf("%d", &n))
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
{
printf("%5d", C(i, j));
}
printf("\n");
}
}
return 0;
}