SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size

Pascal Triangle in Turbo C++

E-mail Print PDF
The code below is written in Turbo C++ to produces a pascal triangle.
#include<iostream.h>
#include<conio.h>

double fact(int n)
{
	if(n==0) return 1;
	else return n*fact(n-1);
}

void main()
{
	clrscr();
	for(int i=0; i<=10;i++)
	{
		for(int j=0; j<=i; j++)
		{
			gotoxy(40-2*i+4*j, 2*i+1);
			cout<<fact(i)/(fact(j)*fact(i-j));
		}
	}
	getch();
}