Share Post:
#include<conio.h>
long factorial(int);
int main()
{
int i, n, c;
printf("Enter the number of rows you wish to see in pascal triangle\n");
scanf("%d",&n);
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");
}
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for( c = 1 ; c <= n ; c++ )
result = result*c;
return ( result );
}
Note:
You need a compiler to compile and execute this code.
#include <stdio.h>Sunday, March 9, 2014
RELATED POSTS
C program to find armstrong number
A number is armstrong if the sum of cubes of individual digits of a number ...
C program to print sum of even numbers upto 10
#include <stdio.h> #include <stdlib.h> int main() { &n ...
C program to print Floyd's triangle.
This program prints Floyd's triangle. Number of rows of Floyd's triangle t ...
C program in order to reverse a number
This program reverses the number given as input by the user. Eg. if user e ...
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment