working out the multiple of a number

This is a discussion on working out the multiple of a number within the C Programming forums, part of the General Programming Boards category; Is there anyway of working out the multiple of an integer that the user types in e.g. user enters 23000 ...

  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
    zen
    zen is offline
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    > 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21