第1个回答 2020-06-27
输入6个字符,例如:
enter
char
1:
8
enter
char
2:
d
enter
char
3:
h
enter
char
4:
K
enter
char
5:
k
enter
char
6:
&
按ASCII码值从大到小输出
k
h
d
K
8
&
程序如下:
#include
<stdio.h>
void
main()
{
unsigned
char
a[6];
int
i,j,tmp;
for(i=0;i<6;i++)
{
printf("enter
char
%d:
",
i+1);
fscanf(stdin,"%c",&a[i]);
fflush(stdin);
};
for
(i=0;i<5;i++)
for
(j=i+1;j<6;j++)
if
(
a[j]>a[i]
)
{
tmp
=
a[j];
a[j]=a[i];
a[i]=tmp;
};
for
(i=0;i<6;i++)
printf("%c
",a[i]);
getch();
}