第一个方法:
#include <stdio.h>
int main()
{int i,j,t,a[10]={98.5,90,67,86.5,77.5,66,100,92,83,78};
for(i=0;i<10;i++)
for(j=0;j<9-i;j++)
if(a[j]<a[j+1])
{t=a[j];a[j]=a[j+1];a[j+1]=t;}
for(i=0;i<10;i++)
printf("%d ",a[i]);
return 0;
方法二:
#include <stdio.h>
int main()
{
float scores[] = {98.5, 90, 67, 86.5, 77.5, 66, 100, 92, 83, 78};
int n = sizeof(scores)/sizeof(scores[0]);
for (int i = 0;i < n - 1;i++)
{
for (int j = 0; j < n - i - 1;j++)
{
if (scores[j] < scores[j + 1])
{
float temp = scores[j];
scores[j] = scores[j + 1];
scores[j + 1] = temp;
}
}
}
printf("排序后的成绩: \n");
for (int i = 0; i < n;i++)
{
printf("%.1f ",scores[i]);
}
printf("\n");
return 0;
}