C++ 程序:打印帕斯卡三角形

原文:https://www.studytonight.com/cpp-programs/program-to-print-pascal-triangle-in-cpp

下面是打印帕斯卡三角形的程序。

#include<conio.h>
#include<iostream.h>

int main()
{
    int n,i,j,c,k,place;

    cout<<"Enter the no of rows: "<<endl;
    cin>>n;
    cout<<" \n\nPASCAL TRIANGLE"<<endl;
    cout<<"\n\n";
    place=n;
        for(i=0;i<n;i++){
            c=1;
            for(k=place;k>=0;k--)
                cout<<" ";

                place--;
            for(j=0;j<=i;j++){
                    cout<<c<<" ";
                    c=(c*(i-j)/(j+1));
                }
            cout<<"\n";

        }
getch();
return 0;
}

输出