C program to print the Pascal’s triangle


Posted Date:     Total Responses: 0    Posted By: Sunil Reddy   Member Level: Gold   Points/Cash: 4   


#include
void main()
{
int a[10][10];
int i,j,c,n;
printf("Enter how many lines do you want");
scanf("%d",&n);
a[1][1]=1;
printf("%5d",a[1][1]);
a[2][1]=1;a[2][2]=2;a[2][3]=1;
printf("%d %d %d",a[2][1],a[2][2],a[2][3]);
for(i=3;i<=n;i++)
{
a[i][1]=1;
printf("%d",a[i][1]);
j=2;c=3;
while(j<=i)
{
a[i][j]=a[i-1][c-1]+a[i-1][c-2];
printf("%5d",a[i][j]);
c=c+1;
j=j+1;
}
a[i][j]=1;
printf("%d",a[i][j]);
}
}


Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: C program for quick sort
Previous Project: C program to find the largest element in an array

Return to Project Index

Post New Project


Related Projects


Complete the action items below to enter to win an iPad Mini from India Study Channel! in India Study Channel - Locker on LockerDome
Awards & Gifts
Active Members
TodayLast 7 Daysmore...

Online Members

Naveen
More...
 
ISC Technologies, Kochi - India. © All Rights Reserved.