Pascal triangle in C.

 

01 #include<stdio.h>
02
03 long fact(int);
04
05 int main()
06 {
07 int line,i,j;
08
09 printf("Enter the no. of lines: ");
10 scanf("%d",&line);
11
12 for(i=0; i<line; i++)
13 {
14 for(j=0; j<line-i-1; j++)
15 {
16 printf(" ");
17 }
18
19 for(j=0; j<=i; j++)
20 {
21 printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
22 }
23 printf("n");
24 }
25
26 return 0;
27 }
28
29 long fact(int num)
30 {
31 long f=1;
32 int i=1;
33
34 while(i<=num)
35 {
36 f=f*i;
37 i++;
38 }
39 return f;
40 }
 
OUTPUT :


Enter the no. of lines: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.