I put together a program that takes a list of numbers in an array and sorts them by copying out of the first array into a second array when the value in the first array matches the maximum array element in the first array. What I cannot figure out is why when I look at the array elements saved in the final array there is a skip in element #10 to #11. In other words the second array correctly saves nine 10's and then skips element #10 and then saves the 9's starting in element #11.
Code:#include <stdio.h> #include <stdlib.h> #define LIMIT 100 int roll[100]; int fin[100]; int num = 0; int main(void) { int cyc = 0; int top = 0; int rotate = 0; int seek = 0; int loop = 0; int temp = 0; while(num < LIMIT) { roll[num] = rand() % 10 + 1; printf("%i",roll[num]); printf("\n"); num++; } for(cyc = 0; cyc < num; cyc++) { if(roll[loop] > roll[loop+1] && roll[loop] > temp) { temp = roll[loop]; } loop++; } for(cyc = 0; cyc < num; cyc++) { loop = 0; //Zero loop for second number to be evaluated while(loop < num) //Go through entire list { if(roll[loop] == temp) //Evaluate whether item matches maximum number { fin[cyc] = roll[loop]; //Copy item in the first array into the final array. cyc++; //Increment cycle by 1. } loop++; //Increment loop to pass through entire list. } temp--; //Decrement number to be evaluated. } }