/*
sort_four.c

A demonstration of passing VARIABLES as parameters to functions.
This demonstrates the use of & and *.

This program reads four numbers and prints them out in sorted 
order.

Ray Ontko 1999/10/12
*/

#include <stdio.h>

void check_swap( float *x , float *y ) ;

int main()
{
  float a , b , c , d ;

  printf( "Enter four numbers\n" ) ;

  scanf( "%f" , &a ) ;
  scanf( "%f" , &b ) ;
  scanf( "%f" , &c ) ;
  scanf( "%f" , &d ) ;

  check_swap( &a , &b ) ;
  check_swap( &b , &c ) ;
  check_swap( &c , &d ) ;
  check_swap( &a , &b ) ;
  check_swap( &b , &c ) ;
  check_swap( &a , &b ) ;

  printf( "In order, the numbers are:\n" ) ;
  printf( "%f\n" , a ) ;
  printf( "%f\n" , b ) ;
  printf( "%f\n" , c ) ;
  printf( "%f\n" , d ) ;

  return 0;
}

/*
check_swap

Checks to see if two float variables are in increasing order, and 
if not, swaps them.  Note that pointers to the variables are passed.
*/
void check_swap( float *x , float *y )
{
  float temp ;

  if ( *x > *y )
  {
    temp = *x ;
    *x = *y ;
    *y = temp ;
  }
}
