用C语言写一个函数,用冒泡法对输入的10个字符按由小到大的顺序排列

写一个函数,用冒泡法对输入的10个字符按由小到大的顺序排列
把这个题目的全部过程写出来,要能在软件上面运行出来的啊.谢谢大家了哦

第1个回答  2007-12-26
maopao(int a[],int num)
{
int i,j,temp;
printf("\nmao pao pai xu\n");
for(i=0;i<=num;i++)
for(j=0;j<=num-1;j++)
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
其接受的实参为一个数组和这个数组元素个数。

全过程
#include<stdio.h>
void main()
{
char c;int x; int a[100];
int i=0,j,num,temp;
clrscr();
printf("please some integers:\n");
scanf("%d", &x);
c=getchar();
while(c!='#')
{ a[i]=x;
scanf("%d", &x);
c=getchar();
i++;
num=i-1;
}
if(num==0)
{
printf("\nYou should give at least two integers!");
exit(0);
}
printf("The integers you input:\n");
for(i=0;i<=num;i++)
{printf("%-5d",a[i]);
if(i%5==4) printf("\n");}
printf("\nmao pao pai xu\n");
for(i=0;i<=num;i++)
for(j=0;j<=num-1;j++)
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
for(i=0;i<=num;i++)
{printf("%-5d",a[i]);
if(i%5==4) printf("\n");}
printf("\nxuan ze pai xu\n");
for(i=0;i<=num;i++)
for(j=i+1;j<=num;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
for(i=0;i<=num;i++)
{printf("%-5d",a[i]);
if(i%5==4) printf("\n");}
getch();
}


不过这是冒泡和选择都有的,你把选择那段程序删了就行了。这是可以通过TC的。
第2个回答  推荐于2018-04-05
void Bubble(char a[] int n)
{
int i,j;
char temp;
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{temp = a[j]; a[j] = a[j+1]; a[j+1] = temp;}
}
}本回答被提问者和网友采纳
第3个回答  2020-04-02
#include
"stdio.h"
#include
"stdlib.h"
void
Bubble(float
a[]){
int
i,j;
float
temp;
for(i=0;i<9;i++)
for(j=0;j<9-i;j++)
{
if(a[j]>a[j+1])
{temp
=
a[j];
a[j]
=
a[j+1];
a[j+1]
=
temp;}
}
}
main()
{
float
B[10],average=0,sum=0;
int
i,j=0;
for(i=0;i<10;i++)
scanf("%f",&B[i]);
for(i=0;i<10;i++)
sum+=B[i];
average
=
sum/10.0;
printf("average
=
%.2f\n",average);
Bubble(B);
for(i=9;i>=0;i--)
{
printf("%.2f\t",B[i]);
++j;
if(j==5)
printf("\n");
}
system("pause");
}
多送你个求平均数
这是我们期末考试的题目
第4个回答  2007-12-26
我的比他们的简单,不用函数调用
#include "stdio.h"
main()
{int i,j,temp,a[10];
clrscr();
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
for(i=0;i<=9;i++)
for(j=0;j<=8-i;j++)
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
for(i=0:i<=9;i++)
printf("%4d",a[i]);}
第5个回答  2020-03-10
void
Bubble(char
a[]
int
n)
{
int
i,j;
char
temp;
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{temp
=
a[j];
a[j]
=
a[j+1];
a[j+1]
=
temp;}
}
}
相似回答