A Program To Add 2 numbers in Dot net


1 simple way to add two number

using System;
namespace Hello
{
    class Hello {     
        static void Main(string[] args)
        {
              int a,b,c; //it is a data type
              Console.WriteLine("Enter 1st number");   //to print message on console window
              a=Convert.ToInt16(Console.ReadLine());   //to take integer input
              System.Console.WriteLine("Enter 2st number");
              b=Convert.ToInt16(Console.ReadLine());
              c=a+b;
             Console.WriteLine("sum is"+c);
            }
       }
}

Meaning of Program:-
int a,b,c; :- It is a type of data type which store the integer type (numeric) value by the given by user.
                   and a,b,c is here variable which store the data temporary.

Convert.ToInt16(Console.ReadLine(); :- here converttoint16 is used to convert the string into                                                                              numbers and Console.ReadLine is a function which read the                                                                  data from console window.

Console.WriteLine("sum is"+c);:- it is used to show the output of c data or sum of a  and b.

Comments

Popular Posts