Write a program that orders three double numbers by increasing value. The progra
ID: 3550715 • Letter: W
Question
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); x
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
the code is :
#include <stdio.h>
void sort3(double* x, double* y, double* z){
double t1,a,b,c;a=*x;b=*y;c=*z;
if(a>b){
t1=a;
a=b;
b=t1;
}
if(b>c){
t1=b;
b=c;
c=t1;
}
if(a>b){
t1=a;
a=b;
b=t1;
}
*x=a;*y=b;*z=c;
}
int main(void) {
double a,b,c;
printf("Enter three numbers: ");
scanf("%lf %lf %lf",&a,&b,&c);
printf(" ");
sort3(&a, &b, &c);
printf("The ordered sequence is: %lf %lf %lf",a,b,c);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.