Skip to content

Commit

Permalink
💡 Documenting source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Sep 26, 2022
1 parent afb99fb commit 4d7fe1e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,44 @@ for (int i = 0; i < 10; i++){
源码地址:
[https://github.com/crossoverjie/gscript-homepage](https://github.com/crossoverjie/gscript-homepage)

## 杨辉三角

```js
int num(int x,int y){
if (y==1 || y ==x) {
return 1;
}
int v1 = num(x - 1, y - 1);
int v2 = num(x - 1, y);
int c = v1+v2;
// int c = num(x - 1, y - 1)+num(x - 1, y);
return c;
}

printTriangle(int row){
for (int i = 1; i <= row; i++) {
for (int j = 1; j <= row - i; j++) {
print(" ");
}
for (int j = 1; j <= i; j++) {
print(num(i, j) + " ");
}
println("");
}
}

printTriangle(7);

// output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
```

---

更多例子:[https://github.com/crossoverJie/gscript/tree/main/example](https://github.com/crossoverJie/gscript/tree/main/example)
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,43 @@ This is a dynamic web application written in `GScript`.
Source code:
[https://github.com/crossoverjie/gscript-homepage](https://github.com/crossoverjie/gscript-homepage)

## YangHui triangle
```js
int num(int x,int y){
if (y==1 || y ==x) {
return 1;
}
int v1 = num(x - 1, y - 1);
int v2 = num(x - 1, y);
int c = v1+v2;
// int c = num(x - 1, y - 1)+num(x - 1, y);
return c;
}

printTriangle(int row){
for (int i = 1; i <= row; i++) {
for (int j = 1; j <= row - i; j++) {
print(" ");
}
for (int j = 1; j <= i; j++) {
print(num(i, j) + " ");
}
println("");
}
}

printTriangle(7);

// output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
```

---

More examples:[https://github.com/crossoverJie/gscript/tree/main/example](https://github.com/crossoverJie/gscript/tree/main/example)
Expand Down

0 comments on commit 4d7fe1e

Please sign in to comment.