Home > Back-end > For help, according to the English reverse output floating point number
For help, according to the English reverse output floating point number
Time:12-02
Recently began to learn C language, see a problem with the book today, made up a, plus or minus an integer can be normal output, but I still want to ask, if the terminal input is a floating point number, how to deal with? How to reverse the normal output? The code is as follows:
/* from the terminal access to a number, according to the English reverse output */ #include #include
Int main (void) { Int inum renum; Bool nsign=true;
Printf (" both Please input a Number: \ n "); The scanf (" % I ", & amp; Inum); If (inum<0) { Printf (" - "); Inum=0 -inum; } Do { If (inum/10!=0) { Renum=inum % 10; Inum=inum/10; } The else { Renum=inum; Nsign=false; } The switch (renum) { Case 0: Printf (" zero "); break; Case 1: Printf (" one "); break; Case 2: Printf (" two "); break; Case 3: Printf (" three "); break; Case 4: Printf (" foru "); break; Case 5: Printf (" five "); break; Case 6: Printf (" six "); break; Case 7: Printf (" seven "); break; Case 8: Printf (" eight "); break; Case 9: Printf (" nine "); break; } } while (nsign); Printf (" \ n \ b "); return 0; }
CodePudding user response:
The first can't use % floating point calculation Second floating point Numbers are not accurate said a number
Opportunistic method Char arr [80]. Sprintf (arr, "% 2" lf, 4.6); Then take the arr