// greatest / smallest among three
#include <iostream>
using namespace std;
int main()
{
int a, b, c, greatest , smallest;
cout<< "Enter three numbers: ";
cin>> a >> b >> c;
if(a>b && a>c)
greatest = a;
else if(b>a && b>c)
greatest = b;
else
greatest = c;
if(a<b && a<c)
smallest = a;
else if(b<a && b<c)
smallest = b;
else
smallest = c;
cout << "Greatest = " << greatest <<endl;
cout << "smallest = " << smallest;
return 0;
}
#include<bits/stdc++.h>
#define MAX 100000
using namespace std;
int Print3Smallest(int array[], int n)
{
int firstmin = MAX, secmin = MAX, thirdmin = MAX;
for (int i = 0; i < n; i++)
{
/* Check if current element is less than
firstmin, then update first, second and
third */
if (array[i] < firstmin)
{
thirdmin = secmin;
secmin = firstmin;
firstmin = array[i];
}
/* Check if current element is less than
secmin then update second and third */
else if (array[i] < secmin)
{
thirdmin = secmin;
secmin = array[i];
}
/* Check if current element is less than
then update third */
else if (array[i] < thirdmin)
thirdmin = array[i];
}
cout << "First min = " << firstmin << "
";
cout << "Second min = " << secmin << "
";
cout << "Third min = " << thirdmin << "
";
}
// Driver code
int main()
{
int array[] = {4, 9, 1, 32, 12};
int n = sizeof(array) / sizeof(array[0]);
Print3Smallest(array, n);
return 0;
}