0

[SOLVED] how to reverse a float number with basic commands(without array, only loops and conditionals)

ex: input: 13.435 output: 534.31

28th Dec 2020, 11:08 AM
athena
athena - avatar
12 ответов
28th Dec 2020, 12:28 PM
Sathish Kanna
Sathish Kanna - avatar
+ 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 😄
28th Dec 2020, 11:13 AM
Matthew
Matthew - avatar
+ 1
🗿MΛƬƬΣӨ🗿 yeah about that i can't use these libraries and these functions.
28th Dec 2020, 11:20 AM
athena
athena - avatar
+ 1
Ipang nope just loops and conditionals
28th Dec 2020, 11:56 AM
athena
athena - avatar
+ 1
🗿MΛƬƬΣӨ🗿 thanks i'll check them
28th Dec 2020, 11:56 AM
athena
athena - avatar
+ 1
Martin Taylor actually i think the only libraries that I'm allowed to use are iostream and math.h and nothing more :)🤦🏻‍♀️
28th Dec 2020, 11:59 AM
athena
athena - avatar
0
What about built-in functions? are you allowed to use them athena ? I just had a theory about it ...
28th Dec 2020, 11:46 AM
Ipang
0
Ipang how does the function work?
28th Dec 2020, 12:00 PM
athena
athena - avatar
0
Aww
28th Dec 2020, 12:26 PM
Kenneth
Kenneth - avatar
0
Sathish Kanna yes it totally works thanks 👍
28th Dec 2020, 12:59 PM
athena
athena - avatar
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
9th Jun 2021, 7:09 AM
Calvin Thomas
Calvin Thomas - avatar