Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Check whether two integers are equal or not


C# Sharp Conditional Statement : Exercise-1 with Solution

Write a C# Sharp program to accept two integers and check whether they are equal or not.

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise1  
{  
    public static void Main()  
    {  
        int int1,int2;
         Console.Write("\n\n");
         Console.Write("Check whether two integers are equal or not:\n");
         Console.Write("-------------------------------------------");
         Console.Write("\n\n");
        Console.Write("Input 1st number: ");  
        int1= Convert.ToInt32(Console.ReadLine());  

        Console.Write("Input 2nd number: ");  
        int2= Convert.ToInt32(Console.ReadLine());  

    if (int1 == int2)
        Console.WriteLine("{0} and {1} are equal.\n",int1,int2);
    else
        Console.WriteLine("{0} and {1} are not equal.\n",int1,int2);
   }  
} 
 

Sample Output:

Check whether two integers are equal or not:                                                               
-------------------------------------------    
Input 1st number: 20                                                                                          
Input 2nd number: 20                                                                                          
20 and 20 are equal.

Pictorial Presentation:

Conditional Statement: Check whether two integers are equal or not.

Flowchart :

Flowchart: Check whether two integers are equal or not.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: C# Sharp Conditional Statement Exercise.
Next: Write a C program to check whether a given number is even or odd.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.