Thread: floating point exception?

  1. #1
    Registered User
    Join Date
    Feb 2011

    floating point exception?

    hey everybody. im was doing a bit of practice to make a programme which would calculate the total resistance and 3 resistors if they were in parallel and in series, when it compiles it keeps saying "floating point exception", can some body please explain what this means. here is the code which i have written:
    int main (void)
        int r1,r2,r3;
        float rp, rs;
        r1 = 2000;
        r2 = 1500;
        r3 = 750;
        printf("the value of 3 resistors are\n");
        printf("r1 = %d\n", r1);
        printf("r2 = %d\n", r2);
        printf("r3 = %d\n\n", r3);
        rs = r1 + r2 + r3;
        rp = 1/((1/r1)+(1/r2)+(1/r3));
        printf("if the resistors were in series\ntotal resistance would be %f\n", rs);
        printf("if the resistors where in parallel\ntotal resistance would be %f\n ", rp);
        return 0;
    and here is the output which keeps popping up:

    the values of the 3 resistors are
    r1 = 2000
    r2 = 1500
    r3 = 750

    floating point exception

  2. #2
    Registered User
    Join Date
    Sep 2008
    Toronto, Canada
    I suggest you declare r1, r2, r3 as float.
    As it is, the formula 1/r1... will give 0 + 0 + 0, and then when you do 1/(0) it's a divide-by-zero problem.

  3. #3
    Registered User
    Join Date
    Feb 2011
    thanks for that man i changed them to a float and it worked fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 12:56 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 10:48 PM
  4. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM