我做了两种方法:
//选择法
#include <iostream>
using namespace std;
main()
{
int a[5],i,j,temp;
printf ("input five numbers:\n");
for (i=0;i<5;i++)scanf ("%d",&a[i]);
for (i=0;i<5;i++)
for (j=i;j<5;j++)
if (a[i]<=a[j]){temp=a[i];a[i]=a[j];a[j]=temp;}
for (i=0;i<5;i++)printf("%d\n",a[i]);
system("PAUSE");
}
//冒泡法
#include <iostream>
using namespace std;
main()
{
int a[5],i,j,temp;
printf ("input five numbers:\n");
for (i=0;i<5;i++)scanf ("%d",&a[i]);
for (i=1;i<5;i++)
for (j=0;j<5-i;j++)
if (a[j]<=a[j+1]){temp=a[j];a[j]=a[j+1];a[j+1]=temp;}
for (i=0;i<5;i++)printf("%d\n",a[i]);
system("PAUSE");
}