Here we written code for print pascal triangle with output.
For improvement of your coding skills we give some tasks along this. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. we will display your details(like Name, City, college, photo) in our site.
Task : Write a c program to print nth line of pascal triangle.
Write a C Program to print Pascal Triangle.
#include<stdio.h>
int main()
{
int i,j,sum,n,sp;
printf(“Enter no.of lines want : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
for(sp=0;sp<(n-i);sp++)
printf(” “);
for(j=0;j<=i;j++)
{
if(i==0||j==0)
sum=1;
else
sum=sum*(i-j+1)/j;
printf(“%d “,sum);
}
printf(“\n”);
}
}
Output:
Enter no.of lines want : 5
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1