Basic Programming C# Examples

C# Program to Check two integers if they are equal or not

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:

  1. using System;: This line includes the System namespace, which contains various classes that support basic data types, such as int, string, and Convert.
  2. namespace EqualIntegersCheck: A namespace is a collection of classes and other data types. The EqualIntegersCheck namespace contains the Program class.
  3. class Program: A class is a blueprint for creating objects. The Program class contains the Main method, which is the entry point for the program.
  4. static void Main(string[] args): The Main method is the starting point of the program. It is static because it can be called without creating an instance of the class. The void keyword indicates that the method does not return a value. The args parameter is an array of strings that contains command-line arguments passed to the program.
  5. Console.WriteLine("Enter first integer: ");: This line displays a message to the user, asking them to enter the first integer.
  6. int num1 = Convert.ToInt32(Console.ReadLine());: This line reads an integer from the user, converts it to an int data type using the Convert.ToInt32 method, and assigns it to the num1 variable.
  7. Console.WriteLine("Enter second integer: ");: This line displays a message to the user, asking them to enter the second integer.
  8. int num2 = Convert.ToInt32(Console.ReadLine());: This line reads an integer from the user, converts it to an int data type using the Convert.ToInt32 method, and assigns it to the num2 variable.
  9. if (num1 == num2): This line checks if num1 is equal to num2 using the equality operator ==.
  10. Console.WriteLine("Both integers are equal.");: If the previous check is true, this line displays a message indicating that the two integers are equal.
  11. else: If the previous check is false, this line executes the code inside the else block.
  12. Console.WriteLine("Both integers are not equal.");: This line displays a message indicating that the two integers are not equal.
  13. Console.ReadLine();: This line waits for the user to press the Enter 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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X