1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // FileName : pascaltriangle.c
4 // Version : 0.10
5 // Author : Ryan Han
6 // Date : 2013/07/01 11:25:30
7 // Comment :
8 //
9 ///////////////////////////////////////////////////////////////////////////////
10 #include <stdio.h>
11 static long GetElement(const long row, const long col)
12 {
13 //1
14 //1 1
15 //1 2 1
16 //1 3 3 1
17 //1 4 6 4 1
18
19 if(1 == col || col == row)
20 return 1;
21 else
22 return GetElement(row - 1, col - 1) + GetElement(row - 1, col);
23 }
24
25 static long PascalTriangle(const long n)
26 {
27 int row, col;
28
29 for(row = 1; row <= n; ++row)
30 {
31 for(col = 1; col <= row; ++col)
32 printf("%4ld", GetElement(row, col));
33 printf("\n");
34 }
35 }
36
37 int main()
38 {
39 PascalTriangle(5);
40 }