0
[SOLVED] how to reverse a float number with basic commands(without array, only loops and conditionals)
ex: input: 13.435 output: 534.31
13 Answers
+ 1
maybe you could try this... https://code.sololearn.com/cK02mwvhuVHd/?ref=app
+ 3
https://code.sololearn.com/c2J99GDYnoOX/?ref=app
This is an example to reverse a STRING in c++, I don't want to give you the whole solution, so all you have to do is change string to float.
Hope I helped you 😄
+ 1
🗿MΛƬƬΣӨ🗿 yeah about that
i can't use these libraries and these functions.
+ 1
Ipang nope
just loops and conditionals
+ 1
🗿MΛƬƬΣӨ🗿 thanks
i'll check them
+ 1
Martin Taylor actually i think the only libraries that I'm allowed to use are iostream and math.h
and nothing more :)🤦🏻♀️
0
What about built-in functions? are you allowed to use them athena ?
I just had a theory about it ...
0
Ipang how does the function work?
0
Aww
0
Sathish Kanna yes it totally works
thanks 👍
0
athena Here's another (yet complex and not-even-nearly-optimised) version:
float flt_rvrs(float num) {
int m = 0;
for (;(int)num<num;m++) num *= 10;
long j = num * 10;
num = 0;
for (int i=1;j/=10;m--) {
if (m < 1) num += (float) (j%10) / (i*=10);
else num = num * 10 + j % 10;
}
return num;
}
// Hope this helps