-
sorting of sorts....hehe
OK so ive been given the task of inputting 10 numbers into an array, making sure that there are at least 2 repeating ones,
for example 1,5,6,6,10,3,5,2,7,8 (6 and 5 repeat)
Having done this, i am to then write a program that sorts them from lowest to highest and eliminates the unnecessary repeating number, so the program would spit out:
1,2,3,5,6,7,8,10 (from the above input)
I havent the slightest clue where to even begin, because the fact that we have to eliminate repeating numbers completley voids the way i was taught to sort arrays.
Any help would be much appreciated,
thanks!
-
well, first create your array (if i'm wrong with any of this, correct me somebdoy)
// create the array and set the numbers to it
int nArray[9] = {1,5,6,6,10,3,5,2,7,8}; // I think this is how
then just use a while or for loop to display the right numbers
-
But those numbers can change, remember?
But this one should be easy, try this: Sort the array (you obviously know how?), and then use a loop to go through each element of the array and print out that element, except if the element before the one to be printed, equals to this one. ie:
if (Array[Element - 1] != Array[Element]) printf("%d", Array[Element]);
You could also add a check to see that Element > 0 to see if you need to check the element before, to avoid any odd errors or such.