Thread: working out the multiple of a number

  1. #1
    Unregistered
    Guest

    Question working out the multiple of a number

    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???

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    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

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  5. help with a source code..
    By venom424 in forum C++ Programming
    Replies: 8
    Last Post: 05-21-2004, 12:42 PM