C++ program to find the smallest element among three elements


In this tutorial, we will be discussing a program to find the smallest element among the provided three elements.

We will be provided with three elements/ integers and our task is to compare them and find the smallest element/ integer among them.

Example

#include <bits/stdc++.h>
using namespace std;
int main() {
   int a = 45, b = 72, c = 10;
   if (a <= b && a <= c)
      cout << a << " is smallest" << endl;
   else if (b <= a && b <= c)
      cout << b << " is smallest" << endl;
   else
      cout << c << " is smallest" << endl;
      return 0;
}

Output

10 is smallest

Updated on: 09-Jul-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements