w3resource

C Exercises: Check whether two integers are equal or not


1. Equality Check

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

Visual Presentation:

Check whether two integers are equal or not


Sample Solution:

C Code:

#include <stdio.h>   // Include the standard input/output header file.

void main()
{
    int int1, int2;   // Declare two integer variables 'int1' and 'int2'.

    printf("Input the values for Number1 and Number2 : ");   // Prompt the user to input values for Number1 and Number2.
    scanf("%d %d", &int1, &int2);   // Read and store the user's input in 'int1' and 'int2'.
    if (int1 == int2)   // Check if Number1 is equal to Number2.
        printf("Number1 and Number2 are equal\n");   // Print a message if Number1 and Number2 are equal.
    else
        printf("Number1 and Number2 are not equal\n");   // Print a message if Number1 and Number2 are not equal.
}

Output:

Input the values for Number1 and Number2 : 15 15                                                              
Number1 and Number2 are equal  

Flowchart:

Flowchart: Check whether two integers are equal or not


For more Practice: Solve these Related Problems:

  • Write a C program to accept three integers and check if at least two of them are equal.
  • Write a C program to compare two integers for equality without using the equality operator.
  • Write a C program to accept two numbers as strings and verify they represent the same integer (accounting for leading zeros).
  • Write a C program to check equality of two integers after reversing their digits.

Go to:


PREV : C Conditional Statement Exercises Home
NEXT : Even or Odd Check.

C Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.