C Program to Check if Two Numbers are Equal

This is a C program to accept two integers and check if they are equal.

Problem Description

This program accepts two integers and check if they are equal or not.

Problem Solution

1. Take the two integers as input.
2. Using if,else statements check if they are equal or not.
3. Print the output accordingly and exit.

Program/Source Code

Here is source code of the C program to accepts two integers and check if they are equal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C program to accept two integers and check if they are equal
  3.  */
  4. #include <stdio.h>
  5. void main()
  6. {
  7.     int m, n;
  8.  
  9.     printf("Enter the values for M and N\n");
  10.     scanf("%d %d", &m, &n);
  11.     if (m == n)
  12.         printf("M and N are equal\n");
  13.     else
  14.         printf("M and N are not equal\n");
  15. }
Program Explanation

1. Take the two integers as input and store it in the variables m and n respectively.
2. Using if,else statements check if m is equal to n.
3. If they are equal, then print the output as “M and N are equal”.
4. Otherwise print it as “M and N are not equal”.

advertisement
advertisement
Runtime Test Cases
Case:1
Enter the values for M and N
3 3
M and N are equal
 
Case:2
Enter the values for M and N
5 8
M and N are not equal

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics of C, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.