fork download
  1. using System;
  2.  
  3. // Define a public class named 'funcexer3'
  4. public class funcexer3
  5. {
  6. // Define a public static method 'Sum' that takes two integer parameters and returns their sum
  7. public static int Sum(int num1, int num2)
  8. {
  9. int total;
  10. total = num1 + num2;
  11. return total;
  12. }
  13.  
  14. // Main method, the entry point of the program
  15. public static void Main()
  16. {
  17. // Print a description of the program
  18. Console.Write("\n\nFunction to calculate the sum of two numbers :\n");
  19. Console.Write("--------------------------------------------------\n");
  20.  
  21. // Prompt the user to enter a number and read the input as an integer
  22. Console.Write("Enter a number: ");
  23. int n1 = Convert.ToInt32(Console.ReadLine());
  24.  
  25. // Prompt the user to enter another number and read the input as an integer
  26. Console.Write("Enter another number: ");
  27. int n2 = Convert.ToInt32(Console.ReadLine());
  28.  
  29. // Calculate the sum by calling the 'Sum' method and print the result
  30. Console.WriteLine("\nThe sum of two numbers is : {0} \n", Sum(n1, n2));
  31. }
  32. }
  33.  
Success #stdin #stdout 0.05s 28832KB
stdin
Standard input is empty
stdout

Function to calculate the sum of two numbers :
--------------------------------------------------
Enter a number: Enter another number: 
The sum of two numbers is : 0