exponents

This is a discussion on exponents within the C Programming forums, part of the General Programming Boards category; after my program calculates the numbers that the user gives it gets a very big nomber to output back to ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    124

    exponents

    after my program calculates the numbers that the user gives it gets a very big nomber to output back to the user.
    ex. 6103515625
    how can i have the program output it back in an exponential form
    ex. 5^14 instead of the big number above

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    1. You'll have to make sure your data type is large enough (for example, 5^14 doesn't fit in a 32-bit integer).
    2. You'll have to find all the prime factors, and their multiplicities (a/k/a their exponents).
    3. For each prime factor, you'll print out the factor and its multiplicity in the form above.

    Unless you know something more specific about the numbers based on how they're calculated.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i have the data type large enough but it keeps printing it out as a long number and i do not understand how to get that number to print as an exponent

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You have to do parts 2 and 3, too.

    Is it supposed to be exact, or can it be approximate (i.e., scientific notation)? If approximate is all you need, then you can cheat a little bit.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i am sorry for being a pain
    but i do not understand what you mean by the explanation that you gave me.
    I am taking my first c course so i do not know much about it
    could you maybe expain in to me in a little bit simpler. thank you

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The point I'm making is that it's not a C problem, it's a math problem. There's not a magic incantation, no % print specification, that will make C print a number in factorized form. If you want it that way, you have to do it. You know how to divide numbers, you know what prime numbers are, off you go.

    With that said, here's the approximate version:

    Code:
    int main(void) {
        long int answer = 6103515625L;
        double approximate = (double)answer;
        printf("%e\n", approximate);
        return 0;
    }
    That will print your number in scientific notation as in "6.10352e9".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exponents are LAAAME
    By Sm33zy in forum C Programming
    Replies: 8
    Last Post: 11-21-2008, 10:10 PM
  2. Fraction Exponents
    By ninjaturtle[k9] in forum C++ Programming
    Replies: 4
    Last Post: 10-18-2004, 11:46 AM
  3. God, i feel like a n00b again. How do i do exponents?
    By Inquirer in forum C++ Programming
    Replies: 13
    Last Post: 09-01-2003, 09:41 PM
  4. how to use exponents
    By guitargatler in forum C++ Programming
    Replies: 11
    Last Post: 02-01-2003, 09:09 PM
  5. For loop and exponents
    By TrazPFloyd in forum C++ Programming
    Replies: 5
    Last Post: 10-15-2002, 06:19 AM

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