Complete the code to call the function greet.
fn greet() {
println!("Hello!");
}
fn main() {
[1];
}To call a function in Rust, you write its name followed by parentheses: greet().
Complete the code to pass the argument name to the function greet.
fn greet(name: &str) {
println!("Hello, {}!", name);
}
fn main() {
greet([1]);
}When passing a string literal to a function expecting &str, use quotes: "Alice".
Fix the error in the function call by completing the blank.
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
let sum = add([1]);
println!("Sum is {}", sum);
}The function add expects two arguments separated by a comma: 5, 3.
Fill both blanks to create a function multiply that returns the product of two numbers and call it correctly.
fn [1](x: i32, y: i32) -> i32 { x [2] y } fn main() { let result = multiply(4, 5); println!("Result is {}", result); }
The function name should be multiply and the operator for multiplication is *.
Fill all three blanks to define a function is_even that returns true if a number is even, and call it with 8.
fn [1](num: i32) -> bool { num [2] 2 == 0 } fn main() { let check = [3](8); println!("Is even? {}", check); }
The function name is is_even, the modulo operator is %, and the call uses is_even.
