一道C语言的题目,求大神解答

输入一个正整数,逐位分割该数的每一位数字,求由数字所构成的最大整数。例如;输入624891,得到最大整数:986421。要求定义和调用函数计算并返回一个x可构成的最大整数。

#include
#define N 20

int fun(int n)
{
int x,t,s[N]={0},i,j,len;
for(len=0;x!=0;len++)
{
x=n/10;
s[len]=n%10;
n=x;
}
for(i=0;i<len-1;i++)
for(j=i;j<len;j++)
{
if(s[i]<s[j])
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
else ;
}
for(i=0,t=0;i<len;i++)
t=t*10+s[i];
return t;
}

int main()
{
int n,max;
printf("input:");
scanf("%d",&n);
max = fun(n);
printf("max = %d\n",max);
return 0;
}

VC中直接运行。。

VS2013调试通过,运行:

102352
532210Press any key to continue . . .
 // ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>

int cmp(const void *a, const void *b)
{
    return *((char *)b) - *((char *)a);
}

int main()
{
    int n = 0;
    scanf_s("%d", &n);
    char ch1[12];
    _itoa_s(n, ch1, 10);
    qsort(ch1, _mbstrnlen(ch1, 12), sizeof(char), cmp);
    printf("%s", ch1);
}