Task: Read two integers and print the larger one using a simple if/else
. If both numbers are equal, print an explicit message.
/*
Program: Maximum of Two Numbers (U1)
What it does:
- Reads two integers x and y from the user.
- Compares them using if/else and prints the larger value.
- If both are equal, prints a special message indicating equality.
*/
#include <stdio.h>
int main(void) {
int x, y;
printf("Enter two integers (x y): ");
if (scanf("%d %d", &x, &y) != 2) {
printf("Invalid input. Please enter two integers.\n");
return 0;
}
/* Compare and print result */
if (x > y) {
printf("Maximum = %d (x is greater than y)\n", x);
} else if (y > x) {
printf("Maximum = %d (y is greater than x)\n", y);
} else {
printf("Both numbers are equal: %d\n", x);
}
/* Example:
Input: x=10 y=3 -> Maximum = 10 (x is greater than y)
Input: x=7 y=9 -> Maximum = 9 (y is greater than x)
Input: x=5 y=5 -> Both numbers are equal: 5
*/
return 0;
}