The simplest way is to copy the first occurance of each number into a second array. Every time you want to move another element, loop through the second array and check that the element doesn't already exist there. If it does then skip it and move on. Here's one way this could be implemented:
Code:
#include <stdio.h>
#include <stdlib.h>
typedef int bool_t;
int main ( void )
{
int a[7] = {1,2,5,1,2,3,3};
/* The value -1 was used here as a placeholder.
** It means that no valid value is here. Just
** make sure that the placeholder isn't in the
** first array. ;)
*/
int b[7] = {-1,-1,-1,-1,-1,-1,-1};
int aIndex, bIndex = 0, check;
bool_t moved;
for ( aIndex = 0; aIndex < 7; aIndex++ ) {
moved = 0;
for ( check = 0; check < aIndex; check++ ) {
if ( a[aIndex] == b[check] )
moved = 1;
}
if ( !moved )
b[bIndex++] = a[aIndex];
}
for ( check = 0; check < 7; check++ ) {
printf ( "%d\t", a[check] );
if ( b[check] != -1 )
printf ( "%d\n", b[check] );
else
printf ( "\n" );
}
return EXIT_SUCCESS;
}
-Prelude