Help me in solving AOCP05 problem

My issue

My code

// Update the '_' in the code below to solve the problem

#include <stdio.h>

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        int n;
        scanf("%d", &n);
        int A[n];
        for (int j = 0; j < n; j++) {
            scanf("%d", &A[j]);
        }
        int minElement = A[0];
        int minElementIndex = 0;
        for (int j = 1; j <=n; j++) {
            if (A[j] < A[j+1]) {
                minElement = A[j];
                minElementIndex = j;
            }
        }
        int j = minElementIndex;
        while (j > 0) {
            int temp = A[j];
            A[j] = A[j-1];
            A[j-1] = temp;
            j--;
        }
        for (int j = 0; j < n; j++) {
            printf("%d ", A[j]);
        }
        printf("\n");
    }
    return 0;
}

Learning course: C for problem solving - 2
Problem Link: CodeChef: Practical coding for everyone

@mahima76
The given problem is a simple code where we are checking the whole array to find minimum element and changing its position.

I have filled the _ in the following code.

// Update the '_' in the code below to solve the problem

#include <stdio.h>

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        int n;
        scanf("%d", &n);
        int A[n];
        for (int j = 0; j < n; j++) { 
            scanf("%d", &A[j]);
        }
        int minElement = A[0];
        int minElementIndex = 0;
        for (int j = 1; j < n; j++) { //running a loop to find minimum element from array
            if (A[j] < minElement) {  // checking if current element is smaller than minimum element 
                minElement = A[j];  // if yes, replacing it as current minimum element 
                minElementIndex = j;
            }
        }
        int j = minElementIndex;
        while (j > 0) { //Shifting the minimum element to the left if it is not already present there
            int temp = A[j];  
            A[j] = A[j-1];
            A[j-1] = temp;
            j--;
        }
        for (int j = 0; j < n; j++) { //printing the array
            printf("%d ", A[j]);
        }
        printf("\n");
    }
    return 0;
}