Twitter Update

Create pascal triangle [C++]


This is program to create Pascal triangle C++ version. this is the code :


#include<iostream.h>
#include<windows.h>
#include<conio.h>
#define N 13
void gotoxy(int x,int y)
{ HANDLE hConsoleOutput;
COORD dwCursorPosition;

cout.flush();
dwCursorPosition.X =x;
dwCursorPosition.Y =y;
hConsoleOutput=GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleCursorPosition (hConsoleOutput,dwCursorPosition);
}
void main()
{

int a[N],b,d[N],n,c;
do{
system("cls");
cout<<"Input number: ";
cin>>n;
}while(n>13);

for(b=0;b<n;b++)
{
    gotoxy(35-(b*2),b+2);
    for(c=0;c<=b;c++)
    {    if(c==b||c==0)
            {
                cout<<"   1";
                d[c]=1;
            }
        else {
            d[c]=a[c]+a[c-1];
            cout<<"   "<<d[c];
        }
    }

    for(c=0;c<=b;c++)
    {
        a[c]=d[c];
    }
   
}
getch();

}

0 comments:

Post a Comment

ABOUT ME

IP
Albert Julius. Powered by Blogger.
Copyright © Albert'Blog