C Program to print Pascal triangle

Program

#include <stdio.h>
long factorial(int);
void main()
{
	int n, i, j;
	printf("Enter the number of rows in Pascal Triangle\n");
	scanf("%d",&n);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j <= (n - i - 2); j++)
			printf(" ");
		for (j = 0 ; j <= i; j++)
			printf("%ld ",fact(i) / (fact(j) * fact(i - j)));
		printf("\n");
	}
}
long fact(int n)
{
	int i;
	long result = 1;
	for (i = 1; i <= n; i++)
		result = result * i;
   return result;
}

Output

Enter the number of rows in Pascal Triangle
8
       1 
      1 1 
     1 2 1 
    1 3 3 1 
   1 4 6 4 1 
  1 5 10 10 5 1 
 1 6 15 20 15 6 1 
1 7 21 35 35 21 7 1