mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-24 04:59:41 +00:00
add solutions for numbers
This commit is contained in:
@ -67,7 +67,7 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
🌟🌟🌟
|
||||
🌟🌟
|
||||
```rust,editable
|
||||
|
||||
// 修改 `assert!` 让代码工作
|
||||
@ -90,9 +90,8 @@ fn main() {
|
||||
let z = 0.01_f64; // f64
|
||||
}
|
||||
```
|
||||
🌟🌟🌟 使用两种方法来让下面代码工作
|
||||
🌟🌟 使用两种方法来让下面代码工作
|
||||
|
||||
> 提示: 1. abs 2. f32
|
||||
|
||||
```rust,editable
|
||||
|
||||
@ -104,7 +103,6 @@ fn main() {
|
||||
### 序列Range
|
||||
🌟🌟 两个目标: 1. 修改 `assert!` 让它工作 2. 让 `println!` 输出: 97 - 122
|
||||
|
||||
> Tips: 使用 `as u8` 将字符 `char` 转换成 `u8` 类型
|
||||
```rust,editable
|
||||
fn main() {
|
||||
let mut sum = 0;
|
||||
@ -114,7 +112,7 @@ fn main() {
|
||||
|
||||
assert!(sum == -3);
|
||||
|
||||
for c in 'a'..='Z' {
|
||||
for c in 'a'..='z' {
|
||||
println!("{}",c);
|
||||
}
|
||||
}
|
||||
@ -136,14 +134,14 @@ fn main() {
|
||||
🌟
|
||||
```rust,editable
|
||||
|
||||
// 填空
|
||||
// 填空,并解决错误
|
||||
fn main() {
|
||||
// 整数加法
|
||||
assert!(1u32 + 2 == __);
|
||||
|
||||
// 整数减法
|
||||
assert!(1i32 - 2 == __);
|
||||
assert!(1u8 - 2 == -1); // 将 u8 修改为另一个类型来让代码工作
|
||||
assert!(1u8 - 2 == -1);
|
||||
assert!(3 * 50 == __);
|
||||
|
||||
assert!(9.6 / 3.2 == 3.0); // error ! 修改它让代码工作
|
||||
|
Reference in New Issue
Block a user