Home » » program for printing pascal triangle in c(very simple)

program for printing pascal triangle in c(very simple)

I used array for printing pascal triangle. Most of the website show solution by calculating factorial and subsequently other methods. Whatever i find them most complex. In this program you need not to cram anything. It's very simple. Just use one simple logic for addition. Let me know if you face any kind of problem.


// Simple Program for Printing Pascal Program in C


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


int printPascal(int row)
{
int a[12][12];

for(int i=0;i<row;i++)
{
for(int 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];
}
}
for(int i=0;i<row;i++)
{
for(int k=i;k<=row-1;k++)
printf(" ");
for(int j=0;j<=i;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}


void main()
{
int n;
printf("Enter Your Number");
scanf("%d",&n);
printPascal(n);
getch();

}


Output :



Share this article :

0 comments:

Post a Comment

 
My Other Websites : Ad Networks | Games Copyright © 2014. Study Depth - All Rights Reserved