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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2.  
  3. public class functionexcercise
  4. {
  5. public static int Sum(int num1, int num2)
  6. {
  7. int total;
  8. total = num1 + num2;
  9. return total;
  10. }
  11.  
  12. public static void Main()
  13. {
  14. Console.Write("Enter two numbers: ");
  15. int number1 = Convert.ToInt32(Console.ReadLine());
  16. int number2 = Convert.ToInt32(Console.ReadLine());
  17. Console.WriteLine("\nThe sum of two numbers is : {0} \n", Sum(number1, number2));
  18.  
  19. Console.ReadLine();
  20. }
  21. }

Result

C# language techstudy

     





Related Topics




Popular Posts