Functions are a fundamental building block in Rust, as in any programming language. They allow you to encapsulate logic and reuse code, making your programs more modular and easier to understand. In this challenge, you will define and implement a series of simple functions that perform basic operations.
Your task is to define three functions:
add(a: i32, b: i32) -> i32
- This function should return the sum of a
and b
.subtract(a: i32, b: i32) -> i32
- This function should return the difference between a
and b
.multiply(a: i32, b: i32) -> i32
- This function should return the product of a
and b
.You need to complete these functions so that they correctly perform the specified operations.
fn
keyword followed by the function name, parameters in parentheses, and the return type.return
keyword or just the last expression in the function body to return a value.pub
keyword to make your functions public so they can be accessed from other modules.