In this program, you'll learn to store and add two integer numbers in C#. After addition, the final sum is displayed on the screen.
C# Program to Add Two Integers
// C# program to add two numbers
using System;
// namespace declaration
namespace App {
class AddTwoNumbers
{
static void Main(String[] args)
{
Console.WriteLine("Enter two numbers");
var first = 10;
var second = 20;
Console.WriteLine(first.ToString() + " " + second.ToString());
// add two numbers
var sum = first + second;
Console.WriteLine("The sum is: " + sum.ToString());
}
}
}
Output:
Enter two numbers
10 20
The sum is: 30
In this program, two integers 10 and 20 are stored in variables first and second respectively.
Then, the first and second are added using the + operator, and its result is stored in another variable sum.
Finally, the sum is printed on the screen using Console.WriteLine() method.
Comments
Post a Comment