Displaying the sum of two numbers input from the keyboard. - CSharp Language Basics

CSharp examples for Language Basics:int

Description

Displaying the sum of two numbers input from the keyboard.

Demo Code

using System;//from  ww  w .  ja  va2  s .co m
class Addition
{
   static void Main()
   {
      int number1; // declare first number to add
      int number2; // declare second number to add
      int sum; // declare sum of number1 and number2
      Console.Write("Enter first integer: "); // prompt user
      // read first number from user
      number1 = int.Parse(Console.ReadLine());
      Console.Write("Enter second integer: "); // prompt user
      // read second number from user
      number2 = int.Parse(Console.ReadLine());
      sum = number1 + number2; // add numbers
      Console.WriteLine($"Sum is {sum}"); // display sum
   }
}

Result


Related Tutorials