Skip to content
Home » Pascal Triangle Program in C Without Using Array

Pascal Triangle Program in C Without Using Array

Learn about Pascal Triangle Program in C Without Using Array in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Pascal Triangle Program in C Without Using Array

To print the pascal triangle as shown below use the below C code.

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

Program:

#include<stdio.h>
int main()
{
  int n;
  printf("Enter the number of rows: ");
  scanf("%d",&n);
  for(int row=1; row<=n; row++)
  {
    int a=1;

    for(int s=1; s<=40-row; s++)
    printf(" ");

    for(int i=1; i<=row; i++)
    {
      printf("%d ",a);
      a = a * (row-i)/i;
    }

    printf("\n");
  }

  return 0;
}

Output:

Enter the number of rows: 5
                                       1 
                                      1 1 
                                     1 2 1 
                                    1 3 3 1 
                                   1 4 6 4 1 

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Pascal Triangle Program in C Without Using Array
Reverse Floyd’s triangle in C