Rust: Getting the factorial of n

Yes, I know writing a factorial function is pretty trivial, but since I am learning Rust from scratch, it is the second program I wrote on it (after the “Hello world”).

This is the code for a recursive factorial in Rust:

fn main()
{
    let r = factorial(9);
    println!("{}", r);
}

fn factorial(n : i64) -> i64
{
    if n == 1 {
        1
    }
    else {
        n * factorial(n - 1)
    }
}

Continue reading “Rust: Getting the factorial of n”

Advertisements

Rust: Hello world

I am starting to learn Rust and I am finding it very very interesting.

Rust is a statically typed, native programming language that pretends to be a nice and modern replacement for C and C++. It implements a very nice set of rules that make your program robust and reliable on memory handling in compile time.

Nice working examples of Rust are the Firefox browser since version 57 (a lot of modules were written in it) [https://blog.mozilla.org/blog/2017/11/14/introducing-firefox-quantum/] and Redox, a UNIX-like operating system written in Rust from the scratch [https://www.redox-os.org/]

So, this is a “Hello world” written in Rust:

Continue reading “Rust: Hello world”