hdu 2032 杨辉三角

杨辉三角

 思路:典型的杨辉三角问题,利用规律,可以计算每个位置的数值

代码:

#include<iostream>
using namespace std;
int main(){

    int n;
    int i, j, num;
    while (cin >> n)
    {
        
            for (i = 1; i <= n; i++)
            {
                num = 1;
                for (j = 1; j <= i; j++)
                {
                    cout << num;
                    num = num*(i - j) / j;
                    if (j < i)
                        cout << " ";
                }
                cout << endl;
            }
            cout << endl;
        
    }
    system("pause");
    return 0;
}

 

原文地址:https://www.cnblogs.com/pcdl/p/12313637.html