Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

why am i getting a Floating point exception?

int get_digit(long number, int position) {

int digit;

digit = number % (10 ^ (position + 1));

digit = digit / (10 ^ position);

return digit;

}

int num_digits(long number) {

int position;

int number_digits = 16;

for (position = 15; position >= 0; position--) {

if (get_digit(number, position) == 0) {

number_digits = number_digits - 1;

}

else {

position = 0;

}

}

return number_digits;

}

i think the problem is coming from the use of these two functions. in particular, the modulus division line. please help!!

Update:

This is C programming by the way.

Update 2:

the error is Floating point exception.... -.-

how do i do exponentiation then? a separate loop?

4 Answers

Relevance
  • 10 years ago
    Favorite Answer

    When you ask for help with an error plese copy & paste the error.

    There's no

    ^

    operator for exponentiation.

    ^ is a bitwise XOR and cannot be used with floats.

    +add

    Use the pow(..) function.

  • 10 years ago

    Um am not that good with C.. but Try replacing all int with float..

  • 10 years ago

    Second contributor is right ^ is XOR operator and not exponent operator as in Excel.

    Include math.h library in your file and call function "pow( number, exponent);"

  • 10 years ago

    That's hard ask a teacher

Still have questions? Get your answers by asking now.