easy
0 views
Two Numbers Equal
Check if two given numbers are equal and print 'yes' or 'no' accordingly.
Understand the Problem
Problem Statement
The program must accept two numbers and print yes if they are equal. Else the program must print no as the output.
Constraints
- The two input numbers must be integers
- The input numbers can be positive, negative, or zero
- The input format must be two space-separated integers
Examples
Example 1
Input
40 40Output
yesExplanation
Since both numbers are 40, they are equal, so the output is 'yes'.
Example 2
Input
50 90Output
noExplanation
Since 50 is not equal to 90, the output is 'no'.
Solution
#include <stdio.h>
int main()
{
int X, Y;
scanf("%d %d", &X, &Y);
printf(X == Y ? "yes" : "no");
return 0;
}Time:O(1)
Space:O(1)
Approach:
The C solution reads two integers using scanf, compares them with the equality operator, and uses the ternary operator to print "yes" or "no" based on the comparison result.
Visual Explanation
Loading diagram...