In this program, we will use an if..else statement to determine which of the two numbers entered is the largest. The computer will first check if the first number is greater than the second one. If it is, then the first number is the largest. Otherwise, if the second number is greater, then it is considered the largest. This simple program demonstrates the use of conditional statements in programming.
#include <stdio.h>
int main() {
int num1 = 20, num2 = 10;
if (num1 > num2)
printf("%d is larger than %d
", num1, num2);
else
printf("%d is larger than %d
", num2, num1);
return 0;
}
#include <iostream>
using namespace std;
int main() {
int num1 = 20, num2 = 10;
if (num1 > num2)
cout << num1 << " is larger than " << num2 << endl;
else
cout << num2 << " is larger than " << num1 << endl;
return 0;
}
num1 = 20
num2 = 10
if num1 > num2:
print(f"{num1} is larger than {num2}")
else:
print(f"{num2} is larger than {num1}")
public class LargestNumber {
public static void main(String[] args) {
int num1 = 20, num2 = 10;
if (num1 > num2)
System.out.println(num1 + " is larger than " + num2);
else
System.out.println(num2 + " is larger than " + num1);
}
}