Program In C To Obtain Pascal's Triangle |
#include <stdio.h> //For standard i/o functions
#include <stdlib.h> //For system("pause")
long factorial(int n) //Defining A Function For Factorial Calculation
{
int c;
long result = 1;
for( c = 1 ; c <= n ; c++ )
result = result*c;
return ( result );
}
int main()
{
int i, n, c;
printf("Enter the number of rows in pascal triangle\n");
scanf("%d",&n); //getting the number of rows
for ( i = 0 ; i < n ; i++ )
{
for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
printf(" ");
for( c = 0 ; c <= i ; c++ )
printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
printf("\n");
}
system("pause");
return 0;
} //End of the program
0 comments:
Post a Comment