find the nth square number in rust

To find the nth square number in Rust, we can use a simple function that multiplies the number n by itself. The nth square number is equal to n².

Here is the code snippet for the function:

main.rs
fn nth_square_number(n: i32) -> i32 {
    return n * n;
}
58 chars
4 lines

This function takes an integer n as input, which represents the nth number for which you want to find the square. It then returns the square of n by multiplying n by itself.

You can use this function to find the 5th square number by calling nth_square_number(5), which will return 25. Similarly, you can use this function to find the square of any number by passing that number as the argument to this function.

gistlibby LogSnag