一.代码
#include <stdio.h>
int Num[100];
int Hang;
int Lie;
int a;
int Flag;
int main() {
Lie = 1;
Hang = 1;
a = 0;
while (1) {
//列1为1
if (Lie == 1) {
Num[1] = 1;
Lie++;
}
//数据存到数组里面
while (Hang >= Lie && Hang != 2) {
if (Hang!=Lie) {
Flag = Num[Lie] + Num[Lie - 1];//列从2开始
}
if (a == 1) {
Num[Lie-1] = Num[0];
a = 0;
}
Num[0] = Flag;
a++;
Lie++;
}
//当列大于行让列等于行
if (Lie > Hang) {
Lie = Hang;
if (Lie>2) {//给一排的倒数第二个赋值
Num[Lie - 1] = Num[0];
}
}
//行等列为1
if (Hang == Lie) {
if (Hang % 2 == 0 && Hang > 2) {
Num[Lie - 1] = Num[0];
}
Num[Hang] = 1;
}
//将这个循环的数组里面的元素全部发送出去
for (int i = 1; i <= Hang; i++) {
printf("%5d", Num[i]);
}
printf("\n");
a = 0;
Lie = 1;
Num[0] = 0;
Hang++;
}
}
二.输出结果