Rust Program: Calculate sum of range of numbers
Write a Rust program that iterates over a range of numbers and calculates the sum of all numbers.
Sample Solution:
Rust Code:
Output:
Sum of numbers from 1 to 10 is: 55
Explanation:
In the exercise above,
- Define the start and end values of the range (inclusive).
- Use the "sum()" method on the range to calculate the sum of all numbers within the range.
- Finally the result is printed to the console.
Rust Code Editor:
Previous: Rust Program: Iterate over vector of integers.
Next: Rust Program: Print length of strings.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.