Write a C# program to add two numbers using function

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
 
public class functionexcercise
{
    public static int Sum(int num1, int num2)
    {
        int total;
        total = num1 + num2;
        return total;
    }
 
    public static void Main()
    {        
        Console.Write("Enter two numbers: ");
        int number1 = Convert.ToInt32(Console.ReadLine());
        int number2 = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("\nThe sum of two numbers is : {0} \n", Sum(number1, number2));
 
        Console.ReadLine();
    }
}

Result

Write a C# program to add two numbers using function
Write a C# program to add two numbers using function

Leave a Comment