Smallest of Two Numbers

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

Example Input/Output 1:
Input:
14 23

Output:
14

Example Input/Output 2:
Input:
5 1

Output:
1

Python

X, Y = map(int, input().split())
print(min(X, Y))

Java

import java.util.*;
public class Hello {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();
        if (num1 < num2) {
            System.out.print(num1);
        } else {
            System.out.print(num2);
        }
    }
}

C

#include <stdlib.h>
#include  <stdio.h>
int main()
{
    int num1, num2;
    scanf("%d%d", &num1, &num2);
    if(num1 < num2)
    {
        printf("%d", num1);
    }
    else
    {
        printf("%d", num2);
    }
}

C++

#include <iostream>
using namespace std;
int main()
{
    int num1, num2;
    cin >> num1 >> num2;
    cout << (num1 < num2 ? num1 : num2);
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.