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

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

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

Comments