Write a C program to check whether two integers are equal or not

Description: Take two integers as input. Print if they are equal or not.

Hint:

  • Use the == operator inside an if statement.

C program to check if two integers are equal

#include <stdio.h>

int main(void) {
    int a, b;

    printf("Enter two integers: ");
    scanf("%d %d", &a, &b);

    if (a == b) {
        printf("The numbers are equal\n");
    } else {
        printf("The numbers are not equal\n");
    }
    return 0;
}

Output:

Output of the above program is

Enter two integers: 15 15
The numbers are equal

How it works

  • a == b is true when both values are the same.
  • Do not write a = b in the condition. It assigns a value and is always true.

Read C If Else Statement.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.