This tutorial demonstrates how to get two inputs from the user within a Console Application. We will learn how to add these numbers.
Variables are defined in the first row. In the next lines, values are assigned to these variables.
In the last line we print the sum of two numbers.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Program { static void Main(string[] args) { int num1, num2, sum; Console.WriteLine("Calculate the sum of two numbers:"); Console.Write("Input number1:"); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Input number2:"); num2 = Convert.ToInt32(Console.ReadLine()); sum = num1 + num2; Console.Write("Result:"+sum); Console.ReadKey(); } } |
Output: