题解 | #争夺前五名#
争夺前五名
http://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
#include <stdio.h>
#include <math.h>
int main()
{
int n = 0;
int grade[40] = {0};
scanf("%d",&n);
int i = 0;
int j = 0;
int temp = 0;
for(i=0; i<n; i++)
{
scanf("%d ",&grade[i]);
}
for(i=0; i<n; i++)
{
for (j=i; j<n; j++)
if (grade[i] < grade[j])
{
temp = grade[i];
grade[i] = grade[j];
grade[j] = temp;
}
}
for (i = 0; i < 5; i++)
{
printf("%d ",grade[i]);
}
return 0;
}