Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

C# Add Two Numbers:


Sure! Adding two numbers in C# is a basic operation. You can do it in various ways, but let's start with a simple console application that prompts the user to enter two numbers and then adds them together.

Here's a straightforward example:

Example

using System;

class Program
{
static void Main(string[] args)
{
// Prompt the user to enter the first number
Console.Write("Enter the first number: ");
string input1 = Console.ReadLine();

// Convert the user input to an integer
int number1 = int.Parse(input1);

// Prompt the user to enter the second number
Console.Write("Enter the second number: ");
string input2 = Console.ReadLine();

// Convert the user input to an integer
int number2 = int.Parse(input2);

// Add the two numbers together
int sum = number1 + number2;

// Display the result
Console.WriteLine("The sum of " + number1 + " and " + number2 + " is: " + sum);
}
}

In this example:

When you run this program, it will prompt you to enter two numbers, add them together, and display the result. It's a simple and basic example to demonstrate adding two numbers in C#.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java