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

CodePudding user response:

reference 1/f, the truth is more important than right or wrong response:
1
can't use % floating point calculationSecond floating point Numbers are not accurate said a number

Opportunistic method
Char arr [80].
Sprintf (arr, "% 2" lf, 4.6);
Then the arr invert

Well, super classes,,, I began to see an , I am familiar with test in two days,
By the way, the nerve to ask a thing, by the way, just try the conditional expression:
 inum/10!=0? (renum=inum % 10, inum=inum/10) : (renum=inum, nsign=false); 
/* if (inum/10!=0)
{
Renum=inum % 10;
Inum=inum/10;
}
The else
{
Renum=inum;
Nsign=false;
} */

Implementation effect is the same, the first look at beautiful view, ask a very super class question for me, for C language, conditional expressions which more efficiency better and IF statements?

CodePudding user response:

reference 1/f, the truth is more important than right or wrong response:
1
can't use % floating point calculationSecond floating point Numbers are not accurate said a number

Opportunistic method
Char arr [80].
Sprintf (arr, "% 2" lf, 4.6);
Then the arr invert

By the way, I want to express clearly or I didn't,
Such as a terminal input a floating point number 123.456, how to output into six five foru three two one;

CodePudding user response:

You need to put the
Inum is defined as a float or double!
Lf the scanf (" % ", & amp; Inum);
  • Related