Yesterday I went for an interview where I have been asked to create a program to find largest and smallest among 5 numbers without using array.
I know how to create
Use a sorting network!
#include
#include
int main()
{
int a, b, c, d, e;
std::cin >> a >> b >> c >> d >> e;
if (a < b) std::swap(a, b);
if (d < e) std::swap(d, e);
if (c < e) std::swap(c, e);
if (c < d) std::swap(c, d);
if (b < e) std::swap(b, e);
if (a < d) std::swap(a, d);
if (a < c) std::swap(a, c);
if (b < d) std::swap(b, d);
if (b < c) std::swap(b, c);
std::cout << "largest = " << a << '\n';
std::cout << "smallest = " << e << '\n';
}