C++练习题7
本帖最后由 as12350992 于 2020-11-29 23:42 编辑Activity 12
Printing Pyramids
Print a pyramid of Pascal’s triangle
Input number of rows: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
活动12
印刷金字塔
打印帕斯卡三角形的金字塔
输入行数:5
1个
1 1
1 2 1
1 3 3 1
1 4 6 4 1
没有解析吗?
#include<iostream>
using namespace std;
int main()
{
int a, b = 1;
cout << "Enter number : ";
cin >> a;
for (int i = 0; i < a; i++)
{
for (int c = 1; c <= a - i; c++)
cout << "";
for (int j = 0; j <= i; j++)
{
if (j == 0 || i == 0)
b = 1;
else
b = b * (i - j + 1) / j;
cout <<b << " ";
}
cout << endl;
}
return 0;
}
页:
[1]