Hi there, if you can do this in C, I\'d appreciate that. We just finished pointe
ID: 3631569 • Letter: H
Question
Hi there, if you can do this in C, I'd appreciate that. We just finished pointers, but haven't gone over arrays yet.
Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is
void sort3(double *x, double *y, double *z);
The function should reorder the values pointed to by its arguments so that after the call
sort3(&x, &y, &z);
the numbers x, y,z satisfy x<=y<=z.
Your program should input data and print results using the following format:
Enter three numbers: 4.7 1.4 3.2
The ordered sequence is: 1.4 3.2 4.7
Explanation / Answer
/* This may help you*/
#include<iostream>
using namespace std;
void sort3(double *x,double *y, double *z)
{
double x=0.0,y=0.0,z=0.0;
x=*x;
y=*y;
z=*z;
if((x>y)&&(x>z))
{
if((y>z)&&(y>x))
{
cout<<z<<y<<x;
}
}
else if((y>x)&&(y>z))
{
if((z>x)&&(z>y))
{
cout<<x<<z<<y;
}
}
else
{
if((x>y)&&(x>z))
{
cout<<y<<x<<z;
}
}
}
int main()
{
double x=0.0,y=0.0,z=0.0;
cout<<"Enter the values of x,y,z";
cin>>x>>y>>z;
sort3(&x,&y,&z);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.