Pages

Monday, 29 January 2018

C# PROGRAM TO ADD TWO NUMBERS / INTEGERS USING METHOD

C# PROGRAM TO ADD TWO NUMBERS / INTEGERS USING METHOD
using System;

namespace AddTwoNumsUsingFunc
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, y, result = 0;
            Console.WriteLine("*** www.ProgrammingPosts.blogspot.com *** ");
            Console.WriteLine(">>>C# PROGRAM TO ADD TWO NUMBERS USING METHOD <<< ");
            Console.Write("\n Enter the first number to be added: ");
            x = Convert.ToInt32(Console.ReadLine());         // taking x value from keyboard
            Console.Write("\n Enter the second number to be added: ");
            y = Convert.ToInt32(Console.ReadLine());         // taking y value from keyboard
            result = Sum(x, y);     //calling function

            Console.WriteLine("\n The sum of two numbers is: {0} ", result);    /*printing the sum.*/
            Console.ReadLine();
        }

        static public int Sum(int a, int b)
        {
            int result = a + b;
            return result;
        }  


    }

}