Create pascal triangle [C]
This program is create pascal triangle by input T of triangle like a picture above, this is the code :
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#define N 13
void gotoxy(int x,int y)
{ HANDLE hConsoleOutput;
COORD dwCursorPosition;
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");
printf("input number:");
scanf("%d",&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)
{
printf(" 1");
d[c]=1;
}
else {
d[c]=a[c]+a[c-1];
printf("%4d",d[c]);
}
}
for(c=0;c<=b;c++)
{
a[c]=d[c];
}
}
getch();
}
Hopefully useful ^_^
Subscribe to:
Post Comments (Atom)
ABOUT ME
Albert Julius. Powered by Blogger.
0 comments:
Post a Comment