-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Mutable Variables Challenge | ||
|
||
Declaring and manipulating variables in programming is a fundamental concept that allows you to store and modify data. Variables in Rust are **immutable by default**, but you can make them mutable using the `mut` keyword. | ||
|
||
In this challenge, you will declare and use **mutable variables in Rust**. You will be given a function where you need to declare variables, modify their values, and perform specific operations. | ||
|
||
## Your task | ||
|
||
In this challenge, you need to declare two mutable variables inside the function using the `let mut` keyword: | ||
|
||
- `x` with an initial value of `5` | ||
- `y` with an initial value of `10` | ||
|
||
Then, perform the following operations: | ||
|
||
1. Increment `x` by `10` | ||
2. Multiply `y` by `2` | ||
|
||
Finally, calculate the sum of `x` and `y` and return the result. | ||
|
||
## Requirements | ||
|
||
- Declare two mutable variables, `x` and `y`, and assign them initial values. | ||
- Increment `x` by `10`. | ||
- Multiply `y` by `2`. | ||
- Calculate the sum of `x` and `y`. | ||
- Return the calculated sum. | ||
|
||
## Example | ||
|
||
```rust | ||
let result = manipulate_variables(); | ||
assert_eq!(result, 35); | ||
``` | ||
|
||
## Hints | ||
|
||
- Use the `let mut` keyword to declare **mutable variables**. | ||
- Use the `+=` operator to increment a variable. | ||
- Use the `\*=` operator to multiply a variable. | ||
- Calculate the sum of `x` and `y` using the `+` operator. | ||
- Either use a `return` statement or an **expression at the end without a semicolon** to return the result. |