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

Write a function that reorders the values in three integer variables such that t

ID: 3532129 • Letter: W

Question

Write a function that reorders the values in three integer variables such that the values are in ascending order .assume that the founction has the following prototype statment:
voide reorder(int *a, int 8b,int *c);
Where a, b, and c are the pointers to the three variables. Write a function that reorders the values in three integer variables such that the values are in ascending order .assume that the founction has the following prototype statment:
voide reorder(int *a, int 8b,int *c);
Where a, b, and c are the pointers to the three variables.

Explanation / Answer

void reorder ( int *a, int * b, int * c)

{

int *temp,*temp1;

if ( * b> * a)

{

if ( *a> * c)

{

temp=a;

a=b;

b=temp;

}

else

{

temp =a;

temp1 =c;

a=b;

b=temp1

c= temp

}

}



the alogorithmm can be interpreted as when a>b>c we dont need to any thing

when b>a>c then we exchange b and a by pointing the address of a to b and address of b to a

when b>>c>a then we exchnage b, a, c into respective positions

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