c语言排序问题,急,加分奖励

来源:百度知道 编辑:UC知道 时间:2024/05/29 02:24:15
输入任意字母,让字母按照从前至后的顺序排列,请问怎么该,现在这个程序是 从后之前排列的
#include <stdio.h>
#include <string.h>
void fun( char t[] )
{
char c;
int i, j;
/**********found***********/
for( i = strlen( t ); i; i-- )
for( j = 0; j < i; j++ )
/**********found***********/
if( t[j] < t[ j + 1 ] )
{
c = t[j];
t[j] = t[ j + 1 ];
t[j + 1 ] = c;
}
}
main()
{
char s[81];
printf( "\nPlease enter a character string: " );
gets( s );
printf( "\n\nBefore sorting:\n \"%s\"", s );
fun( s );
printf( "\nAfter sorting decendingly:\n \"%s\"\n", s );
}
请重点给出改动的部分,谢谢

第一种
#include <stdio.h>
#include <string.h>
void fun( char t[] )
{
char c;
int i, j;
/**********found***********/
for( i = strlen( t ); i; i-- )
for( j = 0; j < i; j++ )
/**********found***********/
if( t[j] <t[ j + 1 ] )
{
c = t[j];
t[j] = t[ j + 1 ];
t[j + 1 ] = c;
}
}
main()
{
char s[81];
printf( "\nPlease enter a character string: " );
gets(s);
printf( "\n\nBefore sorting:\n \"%s\"", s );
fun(s);
printf( "\nAfter sorting decendingly:");
for(int i=strlen(s)-1;i>=0;i--)//从后往前打印
printf("%c",s[i]);
}

第二种:
#include <stdio.h>
#include <string.h>
void fun( char t[] )
{
char c;
int i, j;
/**********found***********/