Q:

Write a program in C# Sharp to create a function for the sum of two numbers

0

Write a program in C# Sharp to create a function for the sum of two numbers. 
Test Data :
Enter a number: 15
Enter another number: 16
Expected Output :
The sum of two numbers is : 31

All Answers

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

using System;
public class funcexer3
{
    public static int Sum(int num1, int num2)
    {
        int total;
        total = num1 + num2;
        return total;
    }     
    public static void Main()
    {
	  Console.Write("\n\nFunction to calculate the sum of two numbers :\n");
      Console.Write("--------------------------------------------------\n");
	  Console.Write("Enter a number: ");
      int n1= Convert.ToInt32(Console.ReadLine());
      Console.Write("Enter another number: ");
      int n2= Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("\nThe sum of two numbers is : {0} \n", Sum(n1,n2) );
    }
}

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now