In: Computer Science
write a C++ program that uses function swap to enter three real value from the keyboard and outputs there in order from minimum to the maximum. For example 10,100,30 if were entered then the output would be 10,30,100. The program should use function get_data(a,b,c) and print_data(a,b,c)
ANS:
#include <string>
#include <iostream>
using namespace std;
void print_data(int a, int b, int c) {
if(a < b && a < c) {
cout << a << ",";
if(b < c) {
cout << b << ",";
cout << c << endl;
}
else if(c < b) {
cout << c << ",";
cout << b << endl;
}
}
else if(b < a && b < c) {
cout << b << ",";
if(a < c) {
cout << a << ",";
cout << c << endl;
}
else if(c < a) {
cout << c << ",";
cout << b << endl;
}
}
else if(c < a && c < b) {
cout << c << ",";
if(a < b) {
cout << a << ",";
cout << b << endl;
}
else if(b < a) {
cout << b << ",";
cout << a << endl;
}
}
}
void get_data(int a, int b, int c) {
cout << "Enter a: ";
cin >> a;
cout << endl << "Enter b: ";
cin >> b;
cout << endl << "Enter c: ";
cin >> c;
cout << endl;
print_data(a, b, c);
}
int main() {
int a1, b2, c2;
get_data(a1, b2, c2);
}
Comment down for any queries
Please give a thumbs up if you are satisfied with answer
:)