题解 | #最高分与最低分之差#
最高分与最低分之差
https://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2
bubble sort
#include <stdio.h>
void bubbleSort(int arr[], int len);
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
bubbleSort(arr, n);
printf("%d\n", arr[n - 1] - arr[0]);
}
return 0;
}
void bubbleSort(int arr[], int len) {
int temp = 0;
for (int i = 0; i < len - 1; i++) {
for (int j = 0; j < len - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}