The idea of bubble sort :

Compare two adjacent elements , If necessary , There needs to be an exchange .

Example 1 :
Use bubble sort to print the top five grades of the class
notes : You need to input the number and score yourself .
such as class 6 personal Output top five results

int main() {
    int arr[40] = { 0 };
    int n = 0;

    scanf("%d", &n);  // The number of input ;
    int i = 0;
    for (i =0; i <n ; i++) {
        scanf("%d", &arr[i]);   // Input n The number of people , Put it in an array 
    }
    for (i = 0; i <n-1 ; i++) {
        int j = 0;
        for (j = 0; j <n-1-i; j++) {
            if (arr[j] > arr[j+1]) {  //   Ascending 

                int tmp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = tmp;
            }
        }
    }
    for (i = n - 1; i >= n - 5; i--) {   // Input    Because it's ascending  --- From the back to the front ---   Top five output 
        printf("%d ", arr[i]);
    }

    return 0;
}

 Use bubble sort to print the top five grades of the class