#include #include #include double calculate_positive_root(int a, int b, int c); double calculate_negative_root(int a, int b, int c); int main() { int a = 2, b = 3, c = 1; double posRoot = calculate_positive_root(a, b, c); double negRoot = calculate_negative_root(a, b, c); printf("The roots of %d*x^2 + %dx + %d are %.2f and %.2f\n", a, b, c, negRoot, posRoot); return 0; } double calculate_positive_root(int a, int b, int c) { double bSqrd = pow(b, 2); double toSqrt = bSqrd - (4 * a * c); if (toSqrt < 0) { printf("Error: cannot calcualte positive root\n"); exit(1); } double sqrtVal = sqrt(toSqrt); return (-1 * b) + sqrtVal; } double calculate_negative_root(int a, int b, int c) { double bSqrd = pow(b, 2); double toSqrt = bSqrd - (4 * a * c); if (toSqrt < 0) { printf("Error: cannot calcualte negative root\n"); exit(1); } double sqrtVal = sqrt(toSqrt); return (-1 * b) - sqrtVal; }