++ Homework 2 Files

This commit is contained in:
Charles Descamps 2023-09-27 20:07:19 -07:00
parent 90652a17ce
commit 6269fbc4ce
10 changed files with 191 additions and 0 deletions

36
Homework2/quadratic.c Normal file
View file

@ -0,0 +1,36 @@
// 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;
}