题解 | #争夺前五名#
争夺前五名
https://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
//BC120 争夺前五名
#include<stdio.h>
void b_sort(short arr[], short n)
{
for (short i = 0; i < n - 1; i++)
{
for (short j = 0; j < n - i; j++)
{
if (arr[j] < arr[j + 1])
{
short tmp = 0;
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
}
void print_arr(short arr[])
{
for (short i = 0; i < 5; i++)
{
printf("%hd ", arr[i]);
}
}
int main()
{
unsigned short n = 0;
short arr[50] = { 0 };
scanf("%hd", &n);
//给遍历数组输入值
for (short i = 0; i < n; i++)
{
scanf("%hd", &arr[i]);
}
b_sort(arr, n);
print_arr(arr);
return 0;
}
传音控股晋升空间 52人发布
