//Project01.cpp
//Date 08/27/2001
//Author Us
//main program and a function to calculate max 2 of 3
#include <iostream.h>
void swap(int &p, int &q)
{
if (p != q)
{
int temp = p;
p = q;
q = temp;
}
}
void max2of3(int a, int b, int c, int &x, int &y)
{
for (int i=1; i<=2; i++)
{
if (a < b)
swap(a, b);
if (b < c)
swap(b, c);
}
x = a;
y = b;
}
void main(void)
{
int x, y;
max2of3(1, 3, 2, x, y);
cout << "max2of3(1, 2, 3) = " << x << ' ' << y << endl;
max2of3(1, 2, 3, x, y);
cout << "max2of3(1, 2, 3) = " << x << ' ' << y << endl;
max2of3(3, 1, 2, x, y);
cout << "max2of3(1, 2, 3) = " << x << ' ' << y << endl;
max2of3(3, 2, 1, x, y);
cout << "max2of3(1, 2, 3) = " << x << ' ' << y << endl;
max2of3(2, 1, 3, x, y);
cout << "max2of3(1, 2, 3) = " << x << ' ' << y << endl;
max2of3(2, 3, 1, x, y);
cout << "max2of3(1, 2, 3) = " << x << ' ' << y << endl;
}
|