Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote