// Copyright © 2016 Talal. All rights reserved. #include #include // this library must be included in order to use built in mathmatical functions such as the square root function int main() { while (1) { //remind the user of the quadratic equation format printf("Quadratic Equation format: aX^2 + bX + c \n"); // declare inputs and outputs and their types float a, b, c, determinant, x1, x2, realSolution, imaginarySolution; // take the inputs from the user, then save them printf("Enter the coefficients a, b, c respectively seperated by a comma \n"); scanf("%f, %f, %f", &a, &b, &c); if (a == 0) { printf("This is not a quadratic equation \n"); break; } // calculate the determinant to determine the number and the type of the solutions determinant = ((b*b) - (4 * a * c)); printf(" Determinant = %f \n", determinant); if (determinant == 0) { // if the determinant is zero, then there will be one real solution x1 = x2 = (-2*b)/ (-2*a); printf("One real solution and it is %0.1f \n”, x1); } else if (determinant > 0) { x1 = ((-b) + sqrtf(determinant))/(2*a); x2 = ((-b) - sqrtf(determinant))/(2*a); printf("Two real solutions and they are %0.1f, and %0.1f \n", x1, x2); } else { // finally, if the determinant is negative, then the solutions will contain an imaginary part realSolution = -b /(2*a); imaginarySolution = sqrtf(-determinant)/(2*a); printf(" Complex Solutions, and they are %0.1f + %0.1fi and %0.1f - %0.1fi \n", realSolution, imaginarySolution, realSolution, imaginarySolution); } } }