For example: when n=3, three positive integer 13312343, connect into the smallest integer 13312343,
And as: n=4, 7,13,4,246 four positive integers, connect into the smallest integer is 1324647,
CodePudding user response:
Fyi:# include & lt; Stdio. H>
#include
#include
Int my_cmp (const void * a, const void * b)
{
Str2 char str1 [10], [10].
Sprintf (str1, "% d", * (int *) a);
Sprintf (str2, "% d", * (int *) b);
Return STRCMP (str1, str2);
}
Int main (void)
{
FILE *fp;
Int a [20], n, I;
/* input values of n */
The scanf (" % d ", & amp; N);
If (n & gt; 20)
{
Printf (" input n & lt;=20 \ n ");
return 1;
}
/* enter */n integers
for(i=0; I & lt; n; I++)
{
The scanf (" % d ", & amp; A [I]);
}
Quick sort/* */
Tree (a, n, sizeof (int), my_cmp);
A file opened/* */
Fp=fopen (" result. TXT ", "w");
If (fp==NULL)
{
Printf (" failed to open the file \ n ");
return 1;
}
/* the output */
for(i=0; I & lt; n; I++)
{
Fprintf (fp, "% d", a [I]);
}
Close the file *//*
fclose(fp);
return 0;
}