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 91 92 93 94 95 96
|
#include <iostream>
#include <cctype>
using namespace std;
int find_min(int num1, int num2);
float find_min(float dnum1, float dnum2);
int find_min(int num1, int num2, int num3);
void get_input(int &num1, int &num2);
void get_input(float &dnum1, float &dnum2);
void get_input(int &num1, int &num2, int &num3);
void print_min(int num1);
void print_min(float dnum1);
int main() {
int num1, num2, num3;
float dnum1, dnum2;
// Two integer version
cout << "Enter two integers: ";
get_input(num1, num2);
print_min(find_min(num1, num2));
cout << "\n";
// Two float version
cout << "Enter two numbers: ";
get_input(dnum1, dnum2);
print_min(find_min(dnum1, dnum2));
cout << "\n";
// Three integer version
cout << "Enter three integers: ";
get_input(num1, num2, num3);
print_min(find_min(num1, num2, num3));
cout << "\n";
return 0;
}
int find_min(int num1, int num2) {
if (num1 == num2) {
return num1;
} else if (num1 < num2) {
return num1;
} else {
return num2;
}
}
float find_min(float dnum1, float dnum2) {
float dmin;
if (dnum1 == dnum2) {
dmin = dnum1;
} else if (dnum1 < dnum2) {
dmin = dnum1;
} else {
dmin = dnum1;
}
return dmin;
}
int find_min(int num1, int num2, int num3) {
int min;
if (num1 == num2 && num1 == num3) {
min = num1;
} else if (num1 < num2 && num1 < num3) {
min = num1;
} else if (num2 < num1 && num2 < num3) {
min = num2;
} else if (num3 < num2 && num3 < num1) {
min = num3;
}
return min;
}
void get_input(int &num1, int &num2) {
cin >> num1 >> num2;
find_min(num1, num2);
}
void get_input(float &dnum1, float &dnum2) {
cin >> dnum1 >> dnum2;
}
void get_input(int &num1, int &num2, int &num3) {
cin >> num1 >> num2 >> num3;
}
void print_min(int num1) {
cout << "The minimum is ";
}
void print_min(float dnum1) {
cout << "The minimun is ";
}
|