A c program to generate the below pascal triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 1
#include <stdio.h>
#include <conio.h>
long calculateFactorial(int number);
void main()
{
int i, n=6, j;
for (i = 0; i < n; i++)
{
for (j = 0;j <= (n - i - 2); j++)
{
printf(" ");
}
for (j = 0 ; j <= i; j++)
{
printf("%ld ",calculateFactorial(i)/(calculateFactorial(j)*calculateFactorial(i-j)));
}
printf("\n");
}
getch();
}
long calculateFactorial(int number)
{
int i;
long result = 1;
for (i = 1; i <= number; i++)
{
result = result*i;
}
return result;
}
Comments
Leave a comment