Program to print stars in Pascal triangle and reverse Pascal - Learn in the easy way

Happy Learning...

ads

Post Top Ad

Program to print stars in Pascal triangle and reverse Pascal

Share This
Code of the program:
#include<iostream>
using namespace std;
int main()
{
          cout<<"\t<<<<< Program to Print Pascal Triangle >>>>>"<<endl;
    int i, j, k;
    for(i=1;i<=5;i++)
    {
        for(j=i;j<5;j++)
        {
          cout << " ";
        }
        for(k=1;k<(i*2);k++)
        {
            cout << "*" ;
        }
        cout <<endl;
    }
    return 0;
}
Output:


Code#2:
#include<iostream>
using namespace std;
int main()
{
             cout<<"\t<<< Program to print star reverse Pascal Triangle"<<endl;
    int i, j, k;
    for(i=5;i>=1;i--)
    {
        for(j=5;j>i;j--)
        {
            cout << " ";
        }
        for(k=1;k<(i*2);k++)
        {
            cout << "*";
        }
        cout <<endl;
    }
    return 0;
}
Output:





No comments:

Post a Comment

Tell me What can I do for you.....Comment, please

Post Bottom Ad

Pages