Skip to content
Solved Examples · Example 22

Q.Write a C program to accept two numbers and check whether they are equal or unequal. The textbook presents this worked program, transcribed exactly as printed (including its printed errors):
#include<stdio.h>  
void main()  
{  
    int m, n;  
printf("Enter the values of M, N\n");  
scanf("%d%d", &m, &n);  
if (m==n)  
printf("Enter the values of M, N\n");  
else  
printf("M and N are not equal\n");  
}  
/*End of main()*/  
Sample output printed in the textbook:
Run 1                            Run 2  
Enter the value of M and N       Enter the value of M and N  
55                               28  
55                               58  
M and N are equal                M and N are not equal  

Karnataka PUCTextbookLongImportance★★★★★est
68% · 104/154 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

[!TLDR]

if (m == n) prints "equal", else prints "not equal"; 55,55 -> equal and 28,58 -> not equal.

This is two-way branching with if-else. Exactly one of the two branches runs on every execution: the true branch when the condition holds and the else branch otherwise, after which control continues past the whole construct. The comparison uses ==, the equality operator (a single = would instead assign n into m). …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.