Must have proper indentation
must use the function swap
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)
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
//header files
#include <iostream>
using namespace std;
//print_data function
void print_data(float a,float b,float c)
{
//printing a,b,c
cout << a << " "<< b << " " << c
;
}
//get_data function
void get_data(float a,float b,float c)
{
//if b < a
if (b < a)
{
//swap a,b
swap(a, b);
}
//if c < b
if (c < b)
{
//swap b,c
swap(b, c);
//after swaping c becomes b
//if b < a
if (b < a)
//swap b,a
swap(b, a);
}
//calling print_data function
print_data(a,b,c);
}
//main function
int main()
{
//initializing variables
float a,b,c;
//printing Enter a number
cout << "Enter a number: ";
//getting input from the user
cin >> a;
//printing Enter a number
cout << "Enter a number: ";
//getting input from the user
cin >> b;
//printing Enter a number
cout << "Enter a number: ";
//getting input from the user
cin >> c;
//calling get_data function
get_data(a,b,c);
//return 0
return 0;
}
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!
Get Answers For Free
Most questions answered within 1 hours.