img
Question:
Published on: 21 November, 2024

Write an program to generate Pascal’s triangle.

Answer:
#include <stdio.h> 
#include <conio.h> 

main()
{
     int a[10][10],i,j,k,n; 
     clrscr();
     printf("Enter the height of the pascal traingle"); 
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
         for(k=1;k<=n-i;k++)
            printf(" "); 
         for(j=0;j<=i;j++)
         {
              if(j==0 || i==j)
                 a[i][j]=1;
              else
                 a[i][j]=a[i-1][j-1]+a[i-1][j];
              printf("%d ",a[i][j]);

         }
         printf("\n");
     }
}
Random questions