The Program in C# Sharp program to accept two integers and check whether they are equal or no given below:
using System;
namespace EqualIntegersCheck
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" Hello Codeauri Family,enter first integer and second integer here to check if the integers are equal or not! : ");
Console.WriteLine("Well,enter first integer here: ");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Similarly, enter second integer: ");
int num2 = Convert.ToInt32(Console.ReadLine());
if (num1 == num2)
{
Console.WriteLine("Okay, both integers are equal.");
}
else
{
Console.WriteLine("Both integers are not equal.");
}
Console.ReadLine();
}
}
}
Output:
Hello Codeauri Family,enter first integer and second integer here to check if the integers are equal or not! :
Well,enter first integer here:
10
Similarly, enter second integer:
10
Okay, both integers are equal.
Pro-Tips💡
Here are the step by step execution of above program:
using System;
: This line includes theSystem
namespace, which contains various classes that support basic data types, such asint
,string
, andConvert
.namespace EqualIntegersCheck
: A namespace is a collection of classes and other data types. TheEqualIntegersCheck
namespace contains theProgram
class.class Program
: A class is a blueprint for creating objects. TheProgram
class contains theMain
method, which is the entry point for the program.static void Main(string[] args)
: TheMain
method is the starting point of the program. It isstatic
because it can be called without creating an instance of the class. Thevoid
keyword indicates that the method does not return a value. Theargs
parameter is an array of strings that contains command-line arguments passed to the program.Console.WriteLine("Enter first integer: ");
: This line displays a message to the user, asking them to enter the first integer.int num1 = Convert.ToInt32(Console.ReadLine());
: This line reads an integer from the user, converts it to anint
data type using theConvert.ToInt32
method, and assigns it to thenum1
variable.Console.WriteLine("Enter second integer: ");
: This line displays a message to the user, asking them to enter the second integer.int num2 = Convert.ToInt32(Console.ReadLine());
: This line reads an integer from the user, converts it to anint
data type using theConvert.ToInt32
method, and assigns it to thenum2
variable.if (num1 == num2)
: This line checks ifnum1
is equal tonum2
using the equality operator==
.Console.WriteLine("Both integers are equal.");
: If the previous check is true, this line displays a message indicating that the two integers are equal.else
: If the previous check is false, this line executes the code inside theelse
block.Console.WriteLine("Both integers are not equal.");
: This line displays a message indicating that the two integers are not equal.Console.ReadLine();
: This line waits for the user to press theEnter
key, which allows them to see the output of the program.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.