杨辉三角形代码:
#include<stdio.h>
int main(){
int a[10][10];
a[0][0] = 1;
//直角
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <= i; j++)
{
if (j == 0 || i == j){
a[i][j] = 1;
}
else
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j <= i; j++)
{
printf("%d ", a[i][j]);
}
printf("\n");
}
}
//等腰只需要在打印语句中加上空白格就行
/* for (int k = 5; k >i; k--)
{
printf(" ");
}*/