w3resource

Rust Functions and Control Flow Exercises with Solutions and Explanations

Rust Functions and Control Flow Exercises [10 exercises with solution and Explanation]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a Rust function that calculates the area of a rectangle given its width and height.

Click me to see the solution

2. Write a Rust function to check if a number is prime.

Click me to see the solution

3. Write a Rust program that implements two functions to find the maximum and minimum numbers in an array.

Click me to see the solution

4. Write a Rust function to calculate the factorial of a given number.

Click me to see the solution

5. Write a Rust function that takes a string and returns the reverse of the string.

Click me to see the solution

6. Write a Rust program that implements a function to calculate the nth Fibonacci number.

Click me to see the solution

7. Write a Rust function to convert a temperature value from Celsius to Fahrenheit.

Click me to see the solution

8. Write a Rust program that defines a function to print the Fibonacci sequence up to a specified number of terms.

Click me to see the solution

9. Write a Rust function to find the sum of all elements in an array.

Click me to see the solution

10. Write a Rust function to check if a string is a palindrome.

Click me to see the solution

Rust Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.