Home:ALL Converter>Execution Stuck in C Program

Execution Stuck in C Program

Ask Time:2017-09-09T09:24:25         Author:NetSec

Json Formatter

I am working through a simple problem set in C to design a quadratic equation solving program, but for some reason I can't get it working. I've tried working through each piece and pulling them into their own programs to test their execution, and individually they seem to work, but when I execute the program, it gets stuck. Any help is appreciated!

//A program to solve a quadratic equation
#include <stdio.h>

float absoluteValue (float x)
{
        if (x < 0)
        x = -x;
        return (x);
}

float squareRoot (float x)
{
        const float epsilon = .00001;
        float guess = 1.0;

        while (absoluteValue (guess * guess - x) >= epsilon )
                guess = (x / guess + guess) / 2.0;
                return guess;
}

float quadraticEquation (float a, float b, float c)
{
         float rootOne, rootTwo;

        if ((b * b - 4 * a * c) <= 0) {
                printf ("The roots are imaginary.");
        }
        else {
                rootOne = (-b + squareRoot(b * b - 4 * a * c)) / (2 * a);
                rootTwo = (-b - squareRoot(b * b - 4 * a * c)) / (2 * a);
        }

        return 0;

}

int main (void)
{
        float a, b, c;
        a = 10;
        b = 30;
        c = 5;

//      printf ("Please enter a value fo A, B, and C: \n");
//      scanf ("%f%f%f", &a, &b, &c);
        quadraticEquation(a, b, c);

        return 0;
}

Author:NetSec,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/46126346/execution-stuck-in-c-program
yy