My program so far creates an array based on a user’s declared size. The program then fills that array with random numbers between 500 and 600 and prints the 4 of those numbers and creates a new line to continue printing them. Everything works fine up to this point. At the part where it is suppose to reprint the numbers in ascending order something goes wrong and it reprints only some of the numbers and not in any order. Any help on how to correct this is appreciated.
int main(){
int size;
int j, i;
int temp;
int a=0;
double sum = 0;
printf("Enter size of array ");
scanf("%d", &size);
int* array;
array=malloc(size * sizeof(*array));
int *aPtr = array;
srand(time(NULL));
for (i = 0; i < size; i++){
aPtr[i] =(rand() % 101) + 500;
printf("%d ", aPtr[i]);
a++;
if (a == 4){
printf("\n");
a = 0;
}
}
printf("\n\n\nIn ascending order\n");
for (i = 0; i< size; i++){
for (j = 0; j < size; j++){
if(aPtr[i] > aPtr[j]);
temp=aPtr[i];
aPtr[i]=aPtr[j];
aPtr[j]=temp;
}
printf("%d\n", aPtr[i]);
}
Problem was a result of the < sign, and the if statement not being in its own brackets. The second for loop for printing also helped print array correctly