# Include <stdio. h>
Bool FTOs (float num, char * s, int N)
{
Int temp;
Float T = num;
Int Pn = 0;
Bool flag_s = true;
Bool flag_z = false;
For (INT I = N; I> 0; I --)
T = T * 10;
Printf ("% F \ n", t );
Temp = T;
Printf ("% d \ n", temp );
If (temp <0)
{
Temp =-temp;
T =-num;
Flag_s = false;
}
If (temp = 0)
{
If (n> 0)
{
For (Pn = 0; PN <n; PN ++)
{
* (S + PN) = '0 ';
}
* (S + PN) = '\.';
++ PN;
}
* (S + PN) = '0 ';
++ PN;
If (! Flag_s ){
* (S + PN) = '\-';
++ PN;
}
* (S + PN) = '\ 0 ';
}
Else
{
While (temp> 0)
{
If (Pn = N & n> 0)
{
* (S + PN) = '\.';
++ PN;
}
Else {
* (S + PN) = (TEMP % 10) + '0 ';
Temp = temp/10;
++ PN;
}
}
While (PN <n)
{
* (S + PN) = '0 ';
++ PN;
}
If (Pn = N)
{
* (S + PN) = '\.';
++ PN;
If (flag_s ){
* (S + PN) = '0 ';
++ PN;
}
}
If (! Flag_s ){
If (T <1.0 ){
* (S + PN) = '\.';
++ PN;
* (S + PN) = '0 ';
++ PN;
}
* (S + PN) = '\-';
++ PN;
}
* (S + PN) = '\ 0 ';
}
Int I (0), J (pn-1 );
While (I <j)
{
Int temp = * (S + I );
* (S + I) = * (S + J );
* (S + J) = temp;
++ I;
J --;
}
Return true;
}
Int main ()
{
Char s [20];
Float num = 123.456;
Int n = 3;
Scanf ("% F", & num );
Scanf ("% d", & N );
Printf ("float num is % F \ n", num );
If (FTOs (Num, S, N ))
{
Printf ("after convert is % s \ n", S );
}
Return 0;
}
Ftoa float type to string