C语言 写一函数用“起泡法”对输入的10个字符由大到小顺序排序

2024-11-30 14:32:11
推荐回答(4个)
回答1:

用VC编写:
#include "iostream.h"
main(void)
{
int i,j;
int t[10];
cout<<"请输入10个数字:";
for(i=0;i<10;i++)
cin>>t[i];
for(i=0;i<9;i++)
{
k=t[i];
for(j=i+1;j<10;j++)
if(t[j] if(k!=t[i]) t[j]=t[i];t[i]=k;
}
for(i=10;i>=0;i--)
cout< }

我给出的程序只能对数字进行排序,字母还要另外编写...没办法一个程序实现...

回答2:

#include "stdio.h"
main()
{int i,j;
char a[10],t
for (i=0;i<10;i++)
{printf("请输入第%d个字符",i);
scanf("%c",&a[i]);}
for (i=0;i<10;i++)
for (j=0;j<10-i;j++)
if (a[j] {t=a[j+1];
a[j+1]=a[j];
a[j]=t;
}
for (i=1;i<10;i++)
printf("%c",a[i]);
}

回答3:

dim i,j,k as integer;
dim a[10] as integer
for i=1 to 10
a[i]=i
next i
for i=0 to 9
for j=0 to i
if a[i]{
k=a[i];
a[i]=a[j];
a[j]=k;
}
next j
next i

回答4:

dim i,j,k as integer;
dim a[10] as integer
for i=1 to 10
a[i]=i
next i
for i=0 to 9
for j=0 to i
if a[i] {
k=a[i];
a[i]=a[j];
a[j]=k;
}
next j
next i