题解 | #小乐乐找最大数#
小乐乐找最大数
https://www.nowcoder.com/practice/ae6a21920cac4f9184c8ecfcc87f89b9
#include <stdio.h>
void BubSort(int arr[]);
int main() {
int a[4];
for (int i = 0; i < 4; i++) {
scanf("%d", &a[i]);
}
// 调用BubSort函数进行数组排序
BubSort(a);
printf("%d\n", a[sizeof(a) / sizeof(int) - 1]);
return 0;
}
void BubSort(int arr[]) {
// Bubble sort
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3 - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}