- The program first declares two variables:
num1 and num2. - It then prompts the user to enter the two numbers using the
printf() and scanf() functions. - An
if statement is used to compare the two numbers. If num1 is greater than num2, the program prints the maximum as num1. Otherwise, it prints the maximum as num2. - Finally, the program returns 0 to indicate successful execution.
- Note that if
num1 and num2 are equal, the program will consider either number as the maximum.
#include <stdio.h>
int main() {
int num1, num2;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
if (num1 > num2) {
printf("Maximum is %d", num1);
} else {
printf("Maximum is %d", num2);
}
return 0;
}
OUTPUT
Enter first number: 12
Enter second number: 45
Maximum is 45