Beginner Β· I/O + parse

Sum of Two Numbers

Read two integers from one line and print their sum β€” the "Hello World" of C# problem solving. The point is the read β†’ parse β†’ compute β†’ print cycle.

Problem

Input: one line with two integers a and b, separated by a space (βˆ’10⁹ ≀ a, b ≀ 10⁹).

Output: a single line with a + b.

Sample:

InputOutput
3 47

Your solution

Program.cs β€” your solution
Custom input for "Run my input"

Judging runs entirely in your browser against hidden tests. Your code is saved locally as you type. Ctrl+Enter judges.

Stuck? Hints

Hint 1 β€” the reading part

Console.ReadLine() gives you the whole line as one string β€” "3 4", not two numbers. line.Split(' ') cuts it into a string[].

Hint 2 β€” text to number

int.Parse("3") turns text into a number. Combine: int a = int.Parse(parts[0]);

Solution (try first!)
string line = Console.ReadLine();
string[] parts = line.Split(' ');
int a = int.Parse(parts[0]);
int b = int.Parse(parts[1]);
Console.WriteLine(a + b);

Four ideas in five lines: read a line, split on spaces, parse each piece, compute and print. Next: make it a loop problem β€” Sum from 1 to N.