加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

从键盘输入一个字符串放在字符数组a中,用选择法将a中的有效字符按降序排列

(2012-03-03 21:32:02)
标签:

it

分类: C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void inOrder(char array[], int n );
int main(int argc, char *argv[])
{
   
    char temp[100];
    printf("请输入字符串:\n");
    gets(temp);
    char a[strlen(temp)+1];
    strcpy(a,temp);
    inOrder(a,strlen(temp));
    int k;
    for(k=0; k<strlen(temp); k++)
    {
       printf("%c",a[k]);    
    }
    system("pause");
    return 0;
}
//选择法排序函数
void inOrder(char array[], int n)
{
    int i, j;
    char  temp;
    for(i=0; i<n-1; i++)
    {
       for(j=i+1; j<n; j++)
       {
            if(array[j]>array[i])
            {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
       
    }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有