Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

C Program to draw Pascal triangle like below

Sample Input 1:

5

Sample Output 1:

    1
   1 1
  1 2 1
 1 3 3 1
1 4 6 4 1

Program or Solution

					    
							
#include<stdio.h>
int main()
{	
	int i,j,n,k,num=1;
	printf("Enter row size:");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-i;j++)
		{
			printf(" ");
		}
		for(k=0;k<=i;k++)
		{
			if (k==0||i==0)
                		num = 1;
            		else
                		num = num*(i-k+1)/k;

            		printf("%4d",num);
		}
		
		printf("\n");
	}
	return 0;
}
					    
					

Program Explanation

Refer Video tutorial