Given three numbers. The task is to find the smallest among given three numbers.

**Examples:**

Input:first = 15, second = 16, third = 10Output:10Input:first = 5, second = 3, third = 6Output:3

**Approach:**

- Check if the first element is smaller than second and third. If yes then print it.
- Else if check if the second element is smaller than first and third. If yes then print it.
- Else third is the smallest element and print it.

Below is the implementation of the above approach:

## C++

`// C++ implementation to find ` `// the smallest of three elements ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `main() ` `{ ` ` ` `int` `a = 5, b = 7, c = 10; ` ` ` ` ` `if` `(a <= b && a <= c) ` ` ` `cout << a << ` `" is the smallest"` `; ` ` ` ` ` `else` `if` `(b <= a && b <= c) ` ` ` `cout << b << ` `" is the smallest"` `; ` ` ` ` ` `else` ` ` `cout << c << ` `" is the smallest"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation to find ` `// the smallest of three elements ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `int` `a = ` `5` `, b = ` `7` `, c = ` `10` `; ` ` ` ` ` `if` `(a <= b && a <= c) ` ` ` `System.out.println( a + ` `" is the smallest"` `); ` ` ` ` ` `else` `if` `(b <= a && b <= c) ` ` ` `System.out.println( b + ` `" is the smallest"` `); ` ` ` ` ` `else` ` ` `System.out.println( c + ` `" is the smallest"` `); ` ` ` ` ` `} ` `} ` `// This code is contributed by shs.. ` |

*chevron_right*

*filter_none*

## Python3

`# Python implementation to find ` `# the smallest of three elements ` ` ` `a, b, c ` `=` `5` `, ` `7` `, ` `10` ` ` `if` `(a <` `=` `b ` `and` `a <` `=` `c): ` ` ` `print` `(a, ` `"is the smallest"` `) ` ` ` `elif` `(b <` `=` `a ` `and` `b <` `=` `c): ` ` ` `print` `(b, ` `"is the smallest"` `) ` `else` `: ` ` ` `print` `(c, ` `"is the smallest"` `) ` ` ` `# This code is contributed ` `# by 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation to find ` `// the smallest of three elements ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `public` `void` `Main () ` `{ ` `int` `a = 5, b = 7, c = 10; ` `if` `(a <= b && a <= c) ` ` ` `Console.WriteLine( a + ` `" is the smallest"` `); ` ` ` `else` `if` `(b <= a && b <= c) ` ` ` `Console.WriteLine( b + ` `" is the smallest"` `); ` ` ` `else` ` ` `Console.WriteLine( c + ` `" is the smallest"` `); ` `} ` `} ` ` ` `// This code is contributed by jit_t ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation to find ` `// the smallest of three elements ` ` ` `// Driver Code ` `$a` `= 5; ` `$b` `= 7; ` `$c` `= 10; ` ` ` `if` `(` `$a` `<= ` `$b` `&& ` `$a` `<= ` `$c` `) ` ` ` `echo` `$a` `. ` `" is the smallest"` `; ` ` ` `else` `if` `(` `$b` `<= ` `$a` `&& ` `$b` `<= ` `$c` `) ` ` ` `echo` `$b` `. ` `" is the smallest"` `; ` ` ` `else` ` ` `echo` `$c` `. ` `" is the smallest"` `; ` ` ` `// This code is contributed ` `// by Akanksha Rai ` |

*chevron_right*

*filter_none*

**Output:**

5 is the smallest

**Time complexity :** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find the Kth smallest element in the sorted generated array
- Find smallest and largest element from square matrix diagonals
- Find the smallest after deleting given elements
- Find the k smallest numbers after deleting given elements
- Find the lexicographically smallest sequence which can be formed by re-arranging elements of second array
- Program to find smallest difference of angles of two parts of a given circle
- Program to find largest element in an array
- Program to find the maximum element in a Matrix
- Find element in array with frequency equal to sum of frequencies of other elements
- Replace every element with the smallest element on its left side
- Program to find the minimum (or maximum) element of an array
- Program to find sum of elements in a given array
- Python program to find sum of elements in list
- Python program to find N largest elements from a list
- Program to find the Product of diagonal elements of a matrix
- Average of remaining elements after removing K largest and K smallest elements from array
- Count of elements which are second smallest among three consecutive elements
- Find element in array that divides all array elements
- Replace every element with the smallest of the others
- Second Smallest Element in a Linked List

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.