For Better Performance Please Use Chrome or Firefox Web Browser

28-1

/* QSORT.C: This program reads the command-line
 * parameters and uses qsort to sort them. It
 * then displays the sorted arguments.
 */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int mycompare( const void *arg1, const void *arg2 );

void main(void)
{
   int i;
   double A[5];

   for( i = 0; i < 5 ; ++i )
      scanf( "%lf", &A[i] );


   /* Sort remaining args using Quicksort algorithm: */
   qsort( (void *)A, 5, sizeof( double ), mycompare );

   /* Output sorted list: */
   for( i = 0; i < 5 ; ++i )
      printf( "%g ", A[i] );
   printf( "\n" );
}

int mycompare( const void *arg1, const void *arg2 )
{
//	return (*((double *)arg1)) - (*((double *)arg2));
	double *ap, *bp;
	ap = (double *)arg1;
	bp = (double *)arg2;
	if (*ap > *bp)
		return 1;
	if (*ap < *bp)
		return -1;
	return 0;
}

تحت نظارت وف ایرانی