Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,955 questions

51,897 answers

573 users

How to calculate the next multiple of 10 in Rust

1 Answer

0 votes
fn next_multiple_of_10(n: i32) -> i32 {
    if n % 10 == 0 {
        n + 10
    } else {
        n + (10 - n % 10)
    }
}

fn main() {
    let nums = [23, 10, 0, 1841];

    for &n in nums.iter() {
        println!("{}", next_multiple_of_10(n));
    }
}


 
 
/*
run:

30
20
10
1850

*/

 



answered Nov 22, 2024 by avibootz

Related questions

1 answer 68 views
1 answer 63 views
1 answer 71 views
1 answer 67 views
1 answer 74 views
1 answer 61 views
...