Is there anyway of working out the multiple of an integer that the user types in
e.g. user enters 23000
I want to show it as 2.3 x 10^4
any solutions???
Is there anyway of working out the multiple of an integer that the user types in
e.g. user enters 23000
I want to show it as 2.3 x 10^4
any solutions???
Something like this -
Code:#include <stdio.h> #include <math.h> int main() { double a = 2300.00; printf("%g x 10^%d",a/pow(10,(int)log10(a)),(int)log10(a)+1); return 0; }
zen
> e.g. user enters 23000
> I want to show it as 2.3 x 10^4
Well the ^4 bit can easily be found by working out the length of the number (sprintf and strlen - mmm - this seems familiar.... )
Also look at printf's %e format