编写一个程序,完成对5个数从大到小的排序,例如输入:1,2,3,4,5,输出的结果为:5,4,3,2,1

来源:百度知道 编辑:UC知道 时间:2024/06/10 16:01:34
速求
用c语言

#include<stdio.h>
void main()
{
int d[101],n,m,i,j;
printf("input number:(end with 0)\n");
n=1;
do
{
scanf("%d",&d[n]);
n++;
}while(d[n-1]!=0);
for(i=n-2;i>0;i--)
for(j=1;j<i;j++)
{
if(d[j]<d[j+1])
{
m=d[j];
d[j]=d[j+1];
d[j+1]=m;
}
}
for(i=1;i<n-1;i++)
printf("%d ",d[i]);
}

输入为0的时候结束输入

#include<malloc.h>
typedef struct Lnode
{
int data;
struct Lnode *next;
}Lnode;

Lnode *createlist(Lnode *L,int n)
{

int i,x;
Lnode *s
L=(Lnode *)malloc(sizeof(Lnode));
L->next=NULL;
for(i=1;i<=n;i++)
{
L=(Lnode *)malloc(sizeof(Lnode))
scanf("%d",&x);
s->data=x;
s->next=L->next;
L->next=s;

}
return L;