Use max and min functions : min « STL Algorithms Min Max « C++ Tutorial





#include <algorithm>
#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
  int x = 4, y = 5;
  cout << "x is " << x << " and y is " << y << endl;
  cout << "Max is " << max(x, y) << endl;
  cout << "Min is " << min(x, y) << endl;
  swap(x, y);
  cout << "x is " << x << " and y is " << y << endl;
  cout << "Max is " << max(x, y) << endl;
  cout << "Min is " << min(x, y) << endl;

  return (0);
}










29.3.min
29.3.1.min
29.3.2.Call min() with special comparison function
29.3.3.Use max and min functions