Floating Point Exception Error

This program compiles fine, but it returns a message “Floating Point Exception” when i run it. I’ve look at other thread the problem appears to be dividing by 0, but i have looked over the program and there’s no division by zero in my entire program. i even used the absolute value function in case

btw the program is meant to reduce fractions

ex input: 6 12 /* 6/12 */
expected output: 1/2

#include <stdio.h>

/*declaring variables*/
int num1, num2, num1b, num2b, gcd, x;
int higher, lower, higher_2, lower_2;

/*declaring functions*/
int find_gcd(int num1, int num2);
void reduce(int numerator, int denominator, int *reduced_numerator, int *reduced_denominator);

int main(void)
{
    do
    {
        printf("enter 2 numbers:  ");
        scanf("%d %d", &num1, &num2);
        reduce(higher, lower, &higher_2, &lower_2);
        printf("enter 0 to end program and any number continue: \n");
        scanf("%d", &x);
    } while(x != 0);

    return 0;
}

void reduce(int numerator, int denominator, int *reduced_numerator, int *reduced_denominator)
{
    num1=numerator;
    num2=denominator;

    gcd =find_gcd(numerator, denominator);

    *reduced_numerator = (numerator/abs(gcd));`enter code here`
    *reduced_denominator = (denominator/abs(gcd));

    printf("The GCD is %d/%d\n", *reduced_numerator, *reduced_denominator);
}

int find_gcd(int m, int n)
{
  while (n != 0) {
    int remainder = m % n;
    m = n;
    n = remainder;
  }
  return m;
}


Download floating.point.exception.error.zip
Direct Link


Download


Download floating.point.exception.error.zip
Mediafire


Download


Download floating.point.exception.error.zip
Netload


Download


Download floating.point.exception.error.zip
Tusfiles


Download


Download floating.point.exception.error.zip
4Shared


Download

Both comments and pings are currently closed.

Comments are closed.