1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
using namespace std;
int smaller (int a, int b) // return the smaller of a and b (if they are equal then just return that value)
{
if (a < b) // if a is less than b, then return a
{
return a; // return value of a
cout << a << endl;
}
else if (b < a) // if b is less than a, then return b
{
return b; // return value of b
cout << b << endl;
}
else //otherwise, if a is not smaller and b is not smaller, then return a or b ...
{
return a; // return value of a since it is equal to b
cout << a << endl;
}
int smallerOfAB = smaller(a, b); // stores the smaller value of a and b into smallerOfAB
}
int bigger (int a, int b) // return the bigger of a and b (if they are equal then just return that value)
{
if (a > b) // if a is greater than b, then return a
{
return a;
}
else if (b > a) // if b is greater than a, then return b
{
return b;
}
else // otherwise, if a is not bigger and b is not bigger, then print ...
{
return a; // return value of a since it is equal to b
}
cout << endl;
int biggerOfAB = bigger(a, b); // stores the bigger value of a and b into BiggerOfAB
cout << biggerOfAB << endl;
}
int smallest (int a, int b, int c) // return the smallest of a, b, and c
{
smaller(a, b);
int smallerOfAB = smaller(a, b);
smaller(smallerOfAB, c);
return smaller(smallerOfAB, c);
int smallestOfABC = smaller (smallerOfAB, c);
}
int biggest (int a, int b, int c) // return the smallest of a, b, and c
{
bigger(a, b);
int biggerOfAB = smaller(a, b);
bigger(biggerOfAB, c);
return bigger(biggerOfAB, c);
int biggestOfABC = bigger(biggerOfAB, c);
}
int middle (int a, int b, int c) // return the middle value of a, b, and c
{
smaller (a, b);
int biggerOfAB = smaller (a, b);
smaller (b, c);
int biggerOfBC = smaller (b, c);
smaller (a, c);
int biggerOfAC = smaller (a, c);
biggest (biggerOfAB, biggerOfBC, biggerOfAC);
return (biggerOfAB, biggerOfBC, biggerOfAC);
}
int main ()
{
int a, b, c;
smaller (1, 2);
cout << a << b;
bigger (1, 2);
smallest (1, 2, 3);
biggest (1, 2, 3);
middle (1, 2, 3);
return 0;
}
|