Here you go...
Code:
#include <stdio.h>
#define RANGE 3
int main(
int argc,
int *argv[]
)
{
int numbers[RANGE], ctr, a, b;
/*
** Read in the numbers ( limit set using RANGE definition above )
*/
for( ctr=0 ; ctr < RANGE ; ctr++ )
{
printf( "\nEnter next number: " );
/** You would normally check for non integers **/
/** before this next statement **/
scanf( "%d", &numbers[ctr] );
}
/*
** Sort the array
*/
for( ctr=0 ; ctr < RANGE ; ctr++ )
{
if( numbers[ctr] < numbers[ctr+1] )
{
/** If the current number is less than the next number, **/
/** swap them round and start again **/
/** I think this is known as a bubble sort **/
a = numbers[ctr];
b = numbers[ctr+1];
numbers[ctr] = b;
numbers[ctr+1] = a;
ctr = -1; /** Effectively restarts loop **/
/** ( -1 because loop executes ctr++ ) **/
}
}
/*
** Print array
*/
printf( "\nNumbers in sorted order:\n\n" );
for( ctr=0 ; ctr < RANGE ; ctr++ )
{
printf( "%d\n", numbers[ctr] );
}
printf( "\n" );
return( 0 );
}
[code][/code]tagged by Salem