C Program to check if two numbers are equal

February 21, 2022, Learn eTutorial

For a better understanding, we always recommend you to learn the basic topics of C programming listed below:

In this c program, we need to check two numbers or integers are equal by accepting two integers using scanf and comparing both the input integer values. For checking that first we need to accept two integers from the user and comparing them with an equal sign, we can get the output of this program. So we first declare two integer variables m and n, then accept two integers and store them in the variable 'm', n', now with the help of an if-else condition statement, we compare the two integers m and n are equal or not. If the integers are equal then display the numbers are equal. Otherwise, display the numbers are not equal.

What is the syntax of the if-else statement?

if (testExpression) {

  // codes inside the body of if

} else {

  // codes inside the body of else


Here if the text expression is True, code inside 'if' statements executed and we skip the else part. But if the text expression is False, the reverse will happen, which means we will execute the else part and skip the if part.


STEP 1: Include the Header files to use the built-in functions in the C program.

STEP 2: Declare the Integer variables m, n.

STEP 3: Read the values of M and N from the user and save them into the variables m and n.

STEP 4: Check if m = n then Display M and N are Equal. Otherwise do step 5.

STEP 5: If m != n then display M and N are not Equal.

C Source Code

                                          #include <stdio.h>

void main() {
  int m, n;
  printf("Enter the values for  M and N\n"); /* user enters the value of  m and n */
  scanf("%d %d", & m, & n);
  if (m == n)
    printf("M and  N are equal\n"); /* After comparing the integers we display equal or not   */
    printf("M and N are not equal\n");
} /* End of main() */


Enter the values for  M and N

34 45
M and N are not equal