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