zoukankan      html  css  js  c++  java
  • Rustlings_functions

    练习过程中的随手记,很多问题也未深究,,简单问题可能直接贴改完之后的代码,..分享出来,若能帮助大家,意外乐趣

    functions1.rs

    // functions1.rs
    // Make me compile! Execute `rustlings hint functions1` for hints :)
    
    fn call_me(){
    
    }
    
    fn main() {
        call_me();
    }
    

    functions2.rs

    // functions2.rs
    // Make me compile! Execute `rustlings hint functions2` for hints :)
    
    
    fn main() {
        call_me(3);
    }
    
    fn call_me(num:i32) {
        for i in 0..num {
            println!("Ring! Call number {}", i + 1);
        }
    }
    

    functions3.rs

    // functions3.rs
    // Make me compile! Execute `rustlings hint functions3` for hints :)
    
    fn main() {
        call_me(1);
    }
    
    fn call_me(num: i32) {
        for i in 0..num {
            println!("Ring! Call number {}", i + 1);
        }
    }
    

    functions4.rs

    // functions4.rs
    // Make me compile! Execute `rustlings hint functions4` for hints :)
    
    // This store is having a sale where if the price is an even number, you get
    // 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
    
    
    fn main() {
        let original_price = 51;
        println!("Your sale price is {}", sale_price(original_price));
    }
    
    fn sale_price(price: i32) -> i32 {
        if is_even(price) {
            price - 10
        } else {
            price - 3
        }
    }
    
    fn is_even(num: i32) -> bool {
        num % 2 == 0
    }
    

    functions5.rs

    // functions5.rs
    // Make me compile! Execute `rustlings hint functions5` for hints :)
    
    
    fn main() {
        let answer = square(3);
        println!("The answer is {}", answer);
    }
    
    fn square(num: i32) -> i32 {
        num * num
    }
    
  • 相关阅读:
    socket http tcp udp ip 协议
    docker启动报错iptables failed: -重建docker0网络恢复
    python3处理json数据
    nginx添加认证
    安装nginx和nginx-gridfs和mongodb
    Centos7下CPU内存等资源监控
    linux 中 iptables关于ping的问题
    python3和pip3安装和问题解决
    Centos7下安装zabbix 3.0.19
    ansible学习网站
  • 原文地址:https://www.cnblogs.com/nightwindnw/p/Rustlings_functions.html
Copyright © 2011-2022 走看看