Pascal Triangle Print This Pattern
Source code :-
#include<stdio.h>
int main()
{
int row,cal,space,i,j;
printf("Enter the number of rows: ");
scanf("%d",&row);
for(i=0;i<row;i++)
{
for(space=1;space<=row-i;space++)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
if(j==0||i==0)
cal=1;
else
cal=cal*(i-j+1)/j;
printf("%d ",cal);
}
printf("\n");
}
return 1;
}
Input-Output :-
abhi@hp-15q-laptop:~$ gcc pascal.c
abhi@hp-15q-laptop:~$ ./a.out
Enter the number of rows: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Post a Comment