Menu
Coddy logo textTech

Recap - Dynamic Input

Part of the Fundamentals section of Coddy's Rust journey — lesson 44 of 75.

challenge icon

Challenge

Beginner

Write a program that gets a dynamic number of input values.

The first input is a number that represents the number of the input values following it. The next input values are whole numbers.

In the end, print the sum of all the input numbers (not including the first input).

 

For example,

Input:

3
1
5
6

Expected output: 12

Explanation:

 1 + 5 + 6 = 12, and there are exactly 3 numbers following the first input number (3).

Try it yourself

use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let count: i32 = input.trim().parse().unwrap();
    // Write your code below

}

All lessons in Fundamentals