Rust Variables and Data Types Exercises with Solutions and Explanations
Rust Variables and Data Types 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 program that declares a variable birth_year and calculates the age based on the current year and the user's birth year.
2. Write a Rust function that calculates the circumference of a circle using the constant PI and a given diameter.
3. Write a Rust function that accepts a mutable reference to a counter variable and increments it by a specified amount.
4. Write a Rust program that declares a boolean variable is_sunny and sets it to true if it's sunny and false otherwise.
5. Write a Rust program that creates an integer variable temp and assign it a temperature value in Celsius. Convert it to Fahrenheit and print the result.
6. Write a Rust program that defines a string variable name and assigns it your name. Print a greeting message using the name variable.
7. Write a Rust program that defines a tuple of coordinates representing latitude and longitude. Print each tuple element separately.
8. Write a Rust program that creates an array of numbers containing 5 integers. Iterate over the array and print each element.
9. Write a Rust program that defines a character variable and assigns it the first letter of your first name.
10. Write a Rust program that creates a vector of items containing different types of items. Print each item in the vector.
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics