floating point exception?

• 03-04-2011
snowball
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:
Code:

```#include<stdio.h> #include<math.h> 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
• 03-04-2011
nonoob
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.
• 03-04-2011
snowball
thanks for that man i changed them to a float and it worked fine.