编程介的小学生 2019-08-12 23:57 采纳率: 20.5%
浏览 330

ASCII码排序,用C怎么做

Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。

Output
对于每组输入数据,输出一行,字符中间用一个空格分开。

Sample Input
qwe
asd
zxc

Sample Output
e q w
a d s
c x z

  • 写回答

1条回答 默认 最新

  • alongname 2019-08-13 10:20
    关注
    #include <stdio.h>
    
    void sort(char *chs);
    
    int main()
    {
        char chs[3];
        printf("Input : ");
        for (int i = 0; i < 3; i++)
            scanf_s("%c", &chs[i]);
        getchar();
        sort(chs);
        printf("Output : ");
        for (int i = 0; i < 3; i++)
            printf("%c ", chs[i]);
        getchar();
    }
    
    void sort(char *chs)
    {
        int i, j;
        int length = sizeof(chs) / sizeof(char) - 1;
        for (i = 0; i < length; i++)
        {
            for (j = i + 1; j < length; j++)
            {
                if (chs[i] > chs[j])
                {
                    char temp = chs[j];
                    chs[j] = chs[i];
                    chs[i] = temp;
                }
            }
        }
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序