CYB126-Projects/Homework2/quadratic.c
2023-09-27 20:07:19 -07:00

36 lines
No EOL
1 KiB
C

// header files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
// local constants
#define QUADRATIC_A 2
#define QUADRATIC_B -4
#define QUADRATIC_C -3
/*
Name: Quadratic Formula Root Finder
Process:
Function input/parameters: NONE
Function output/parameters: NONE
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int main()
{
// define local variables
double positiveRoot, negativeRoot;
// do calculations
positiveRoot = (-QUADRATIC_B + sqrt((QUADRATIC_B * QUADRATIC_B) -
(4 * QUADRATIC_A * QUADRATIC_C))) / (2*QUADRATIC_A);
negativeRoot = (-QUADRATIC_B - sqrt((QUADRATIC_B * QUADRATIC_B) -
(4 * QUADRATIC_A * QUADRATIC_C))) / (2*QUADRATIC_A);
// display results
printf("The roots of the quadratic %dx^2 + %dx + %d are: %f & %f.\n",
QUADRATIC_A, QUADRATIC_B, QUADRATIC_C, positiveRoot, negativeRoot);
// return success
return 0;
}