PASCAL’S TRIANGLE;

QUES- WAP  to print the pascals triangle after taking the input from user;

ANSWER-

#include<stdio.h>
#include<conio.h>
long int cal(int);
int main()
{
int i,j,r,p;
printf(“\nNo. of rows you need : “);
scanf(“%d”,&r);
for(i=0;i<r;i++)
{
for(j=0;j<=(r-i-1);j++)
printf(” “);
for(j=0;j<=i;j++)
{
p=cal(i)/(cal(j)*cal(i-j));
printf(“%ld “,p);
}
printf(“\n”);
}
printf(“\n\nPROGRAMMING AT C#ODE STUDIO”);
getch();
return 0;
}

long int cal( int num)
{
int x;
long r=1;
for(x=1; x<=num; x++)
r=r*x;
return (r);
}

pascal

Leave a comment