#include<stdio.h>
#include<algorithm>
usingnamespacestd;
#definemaxn1000
inta[maxn];
boolcmp(inta,intb){
returna>b;
}
intmain()
{
inti,n;
printf("請輸入要排序的元素個數:");
scanf("%d",&n);
printf("請依次輸入%d個數:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
printf("%3d",a[i]);
return0;
#include<stdio.h>
#include<algorithm>
usingnamespacestd;
#definemaxn1000
inta[maxn];
boolcmp(inta,intb){
returna>b;
}
intmain()
{
inti,n;
printf("請輸入要排序的元素個數:");
scanf("%d",&n);
printf("請依次輸入%d個數:",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
for(i=0;i<n;i++)
printf("%3d",a[i]);
return0;
}