/* ECP: FILEname=fig7_5.c */ /* 1*/ #include /* 2*/ /* Print Up To MaxN Integers, But Avoid Duplicates */ /* 3*/ #define MaxN 10 /* 4*/ main( void ) /* 5*/ { /* 6*/ int Num[ MaxN ], Tmp; /* 7*/ int j, Counter, ItemsRead = 0; /* 8*/ /* Read Input */ /* 9*/ printf( "Enter up to %d integers: ", MaxN ); /*10*/ while( ItemsRead < MaxN && scanf( "%d", &Num[ ItemsRead ] ) > 0 ) /*11*/ ItemsRead++; /*12*/ /* Sort Input, Using Insertion Sort */ /*13*/ for( Counter = 1; Counter < ItemsRead; Counter++ ) /*14*/ { /*15*/ Tmp = Num[ Counter ]; /*16*/ for( j = Counter; j > 0 && Tmp < Num[ j - 1 ]; j-- ) /*17*/ Num[ j ] = Num[ j - 1 ]; /*18*/ Num[ j ] = Tmp; /*19*/ } /*20*/ /* Output Non-Duplicates */ /*21*/ printf( "%d", Num[ 0 ] ); /*22*/ for( Counter = 1; Counter < ItemsRead; Counter++ ) /*23*/ if( Num[ Counter ] != Num[ Counter - 1 ] ) /*24*/ printf( " %d", Num[ Counter ] ); /*25*/ printf( "\n" ); /*26*/ return 0; /* Normal Exit */ /*27*/ }