题解 | #公务员面试#
公务员面试
http://www.nowcoder.com/practice/f3a134908d5b41869f14f58307008a97
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h>
void bubble(int arr[], int a) { int j = 0; int i = 0; int flag = 0;
for (i = 0; i < a - 1; i++)
{
flag = 0;
for (j = 0; j < a - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int tmp = 0;
tmp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = tmp;
flag = 1;
}
}
if (flag == 0)
break;
}
}
int main() { int arr[7] = { 0 }; double x = 0; int sum = 0; int i = 0; for (i = 0; i < 7; i++) { scanf("%d", &arr[i]); } bubble(arr, 7); sum = arr[1] + arr[2] + arr[3] + arr[4] + arr[5]; x = sum / 5.0; printf("%.2lf\n", x); return 0; }