mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 02:03:10 +08:00
build
This commit is contained in:
@ -151,7 +151,7 @@ The following function implements the sum $1 + 2 + \dots + n$ using a `for` loop
|
||||
res += i;
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
@ -352,6 +352,7 @@ Below we use a `while` loop to implement the sum $1 + 2 + \dots + n$:
|
||||
fn while_loop(n: i32) -> i32 {
|
||||
let mut res = 0;
|
||||
let mut i = 1; // 初始化条件变量
|
||||
|
||||
// 循环求和 1, 2, ..., n-1, n
|
||||
while i <= n {
|
||||
res += i;
|
||||
@ -570,6 +571,7 @@ For example, in the following code, the condition variable $i$ is updated twice
|
||||
fn while_loop_ii(n: i32) -> i32 {
|
||||
let mut res = 0;
|
||||
let mut i = 1; // 初始化条件变量
|
||||
|
||||
// 循环求和 1, 4, 10, ...
|
||||
while i <= n {
|
||||
res += i;
|
||||
|
Reference in New Issue
Block a user