字符串str中找出最大的字符并放在第一个位置上,并将将字符前的原字符往后顺序移动。

#include <stdio.h>
int main(){
  char str[80], *p, max, *q;
  p=str; 
  gets(p); 
  max=*(p++);
  while(*p != '\0')
  {   if(max<*p){ 
  		max=*p;  
		q=p;}
      	p++;
}
  p=q;
  while( p>&str[0]) 
  { *p=*(p-1);  
	p--; }
	*p=max;
  puts(p);
  return 0;
}
发布了42 篇原创文章 · 获赞 13 · 访问量 1927

猜你喜欢

转载自blog.csdn.net/KEVINzzh/article/details/103794936