习题集

 

/*对于长度为7个的字符的字符串,除首、尾字符外,将其余的5个字符按ASCII
码的值升序排列。例如:原来的字符串为:BdsihAd,则排序后输出为BAdhisd.*/

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
char *fun(char *s,int num)
{
 char t;
 int i,j;
 for(i=1;i<num-2;i++)
  for(j=i+1;j<num-1;j++)
   if (s[i]>s[j])    /*比较*/
   {                 /*交换*/
    t=s[i];
    s[i]=s[j];
    s[j]=t;
   }
  return s;
}


 

 

main()
{
 char s[10];   /*定义字符数组*/
 printf("输入7个字符的字符串");
 gets(s);
 fun(s,7);
 printf("\n%s",s);
}

posted @ 2009-03-24 22:40  ThirdEye  阅读(136)  评论(0编辑  收藏  举报