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

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

Sabari M
Sabari M
Software Professional, India

IT professional with 14+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.techieclues.com/profile/alagu-mano-sabari-m

Comments (0)

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