Write a program to check for the relation between 2 nos
#include <stdio.h> int main() { int num1, num2; // Input two numbers from user printf("Enter first number: "); scanf("%d", &num1); printf("Enter second number: "); scanf("%d", &num2); // Check and display the relationship if (num1 > num2) { printf("%d is greater than %d\n", num1, num2); } else if (num1 < num2) { printf("%d is less than %d\n", num1, num2); } else { printf("%d is equal to %d\n", num1, num2); } return 0; }
Explanation:
-
The program takes two integers as input from the user.
-
It uses
if
,else if
, andelse
statements to compare the two numbers. -
Depending on the condition:
-
If the first number is greater, it prints “
num1
is greater thannum2
“. -
If the first number is smaller, it prints “
num1
is less thannum2
“. -
If both are equal, it prints “
num1
is equal tonum2
“.
-