easy
1 views

Largest of Two Numbers

Write a program that accepts two numbers and prints the largest number.

Understand the Problem

Problem Statement

The program must accept two numbers and print the largest number.

Constraints

  • The input consists of exactly two integers separated by a space.
  • Both numbers are valid integers within standard integer range for the programming language.
  • No special characters or invalid input need to be handled.

Examples

Example 1
Input
12 25
Output
25
Explanation

Since 25 is greater than 12, 25 is printed as the largest number.

Example 2
Input
9 5
Output
9
Explanation

Since 9 is greater than 5, 9 is printed as the largest number.

Solution

#include <stdio.h>

int main() {
    int num1, num2;
    scanf("%d %d", &num1, &num2);
    
    if (num1 > num2) {
        printf("%d", num1);
    } else {
        printf("%d", num2);
    }
    
    return 0;
}
Time:O(1)
Space:O(1)
Approach:

The C solution reads two integers using scanf, then uses an if-else statement to compare them. If num1 is greater than num2, it prints num1; otherwise, it prints num2. The program returns 0 to indicate successful execution.

Visual Explanation

Loading diagram...