Q:

Write a C# program to add two numbers using function

0

Write a C# program to add two numbers using function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter two numbers: 50

30

The sum of two numbers is : 80

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C# program to create a function to input a... >>
<< Write a C# program to create a user define functio...