← C# from Scratch Lesson 20 of 39 · 5 XP

Warm-up: sum of a line of numbers warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

Split(' ') cuts a line at spaces and gives an array of strings. You can walk through it with foreach:

string[] parts = Console.ReadLine().Split(' ');
int sum = 0;
foreach (string p in parts)
{
    sum += int.Parse(p);
}

Task. Read a line of integers separated by spaces and print their sum.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.