Simple C# console program to input two integers, calculate their sum, and display the result. Ideal for beginners learning basic I/O and arithmetic.
using System;
namespace CalcolatriceSomma
{
class Program
{
static void Main(string[] args)
{
// Variables to store the entered numbers
int numero1, numero2;
// Request and read the first number
Console.WriteLine("Inserisci il primo numero intero:");
string input1 = Console.ReadLine();
// Check that the input is a valid number
if (!int.TryParse(input1, out numero1))
{
Console.WriteLine("Errore: il valore inserito non è un numero intero valido.");
return; // Terminate the program
}
// Request and read the second number
Console.WriteLine("Inserisci il secondo numero intero:");
string input2 = Console.ReadLine();
// Check that the input is a valid number
if (!int.TryParse(input2, out numero2))
{
Console.WriteLine("Errore: il valore inserito non è un numero intero valido.");
return; // Terminate the program
}
// Calculate the sum
int somma = numero1 + numero2;
// Display the result
Console.WriteLine($"La somma di {numero1} e {numero2} è: {somma}");
}
}
}Software: .NET SDK (version 6.0 or higher recommended) to compile and run the program.
Software: Text editor or IDE (Visual Studio, Visual Studio Code, Rider, etc.) to write C# code.
Configuration: no external libraries needed, the program uses only the standard System library.
Hardware: any computer with Windows, Linux, or macOS operating system supporting .NET.
Links/Config: no special configuration required, the program runs from console/terminal.