Problem statement:- Program to Find the smallest of three numbers.
Example:
Input: 7 3 8
Output: 3
Input: -777 888 -7456
Output: -7456
Data requirement:-
Input Data:-num1, num2, num3
Output Data:-min
Output Data:-min
Program in C
Here is the source code of the C Program to Find the smallest of three numbers.
Code:
#include<stdio.h>
#include<limits.h>
int main()
{
int num1,num2,num3;
printf("Enter 3 numbers:");
scanf("%d %d %d",&num1,&num2,&num3);
int min=INT_MAX;
if(num1<min)
min=num1;
if(num2<min)
min=num2;
if(num3<min)
min=num3;
printf("The smallest number is %d",min);
}
Input/Output:
Enter 3 numbers:
-777
888
-7456
The Smallest number is -7456
Program in C++
Here is the source code of the C++ Program to Find the smallest of three numbers.
Code:
#include<iostream>
using namespace std;
int main()
{
int num1,num2,num3;
cout<<"Enter 3 numbers:";
cin>>num1>>num2>>num3;
int min=INT_MAX;
if(num1<min)
min=num1;
if(num2<min)
min=num2;
if(num3<min)
min=num3;
cout<<"The smallest number is "<<min;
}
Input/Output:
Enter 3 numbers:
-547
789
125
The smallest number is -547
Program in Java
Here is the source code of the Java Program to Find the smallest of three numbers.
Code:
import java.util.Scanner;
public class SmallestNumber {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num1,num2,num3;
System.out.println("Enter 3 numbers:");
num1=cs.nextInt();
num2=cs.nextInt();
num3=cs.nextInt();
int min=Integer.MAX_VALUE;
if(num1<min)
min=num1;
if(num2<min)
min=num2;
if(num3<min)
min=num3;
System.out.println("The Smallest number is "+min);
cs.close();
}
}
Input/Output:
Enter 3 numbers:
-777
888
-7456
The Smallest number is -7456
Program in Python
Here is the source code of the Python Program to Find the smallest of three numbers.
Code:
print("Enter 3 numbers:")
num1=int(input())
num2=int(input())
num3=int(input())
print("The smallest number is ",min(num1,num2,num3))
num2=int(input())
num3=int(input())
print("The smallest number is ",min(num1,num2,num3))
Input/Output:
Enter 3 numbers:
77
-25
99999
The smallest number is -25
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box