-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpascaltriangel.cpp
49 lines (41 loc) · 907 Bytes
/
pascaltriangel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* =====================================================================================
*
* Filename: pascaltriangel.cpp
*
* Description: 杨辉三角
*
* Version: 1.0
* Created: 2015年03月25日 20时39分36秒
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <iostream>
using namespace std;
int getElem(int row, int col)
{
if (col == 1 || row == col) {
return 1;
}
return getElem(row-1,col) + getElem(row-1, col-1);
}
void triangel(int n)
{
for(int row = 1; row <=n; ++row) {
for (int col = 1; col <=row; ++col) {
cout << getElem(row, col) << " ";
}
cout << endl;
}
}
int main()
{
int n = 5;
triangel(5);
return 0;
}