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

C++Server Side ProgrammingProgramming

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
raja
Published on 21-Nov-2019 13:05:49
Advertisements