TechieClues TechieClues
Updated date Feb 22, 2021
This code snippet helps you to understand how to calculate the sum of two numbers in C# and will be useful for beginners or fresh C# developers.
  • 1.2k
  • 0
  • 0

This code snippet helps you to understand how to calculate the sum of two numbers in C# and will be useful for beginners or fresh C# developers.

using System;
public class SumTwoNumbers
{
    public static int Sum(int number1, int number2)
    {
        int total;
        total = number1 + number2;
        return total;
    }

    public static void Main()
    {
        Console.Write("\n\nSum of two numbers :\n");
        Console.Write("--------------------------------------\n");
        Console.Write("Enter 1st number: ");
        int num1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter 2nd number: ");
        int num2 = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("\nSum of two numbers : {0} \n", Sum(num1, num2));
        Console.ReadKey();
    }
}

Output:

Sum of two numbers :
-----------------------------
Enter 1st number: 25
Enter 2nd number: 50

Sum of two numbers: 75

 

ABOUT THE AUTHOR

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

There are no comments. Be the first to comment!!!