/********************************************************* * From C PROGRAMMING: A MODERN APPROACH, Second Edition * * By K. N. King * * Copyright (c) 2008, 1996 W. W. Norton & Company, Inc. * * All rights reserved. * * This program may be freely distributed for class use, * * provided that this copyright notice is retained. * *********************************************************/ /* quadratic.c (Chapter 27, page 723) */ /* Finds the roots of the equation 5x**2 + 2x + 1 = 0 */ #include #include int main(void) { double a = 5, b = 2, c = 1; double complex discriminant_sqrt = csqrt(b * b - 4 * a * c); double complex root1 = (-b + discriminant_sqrt) / (2 * a); double complex root2 = (-b - discriminant_sqrt) / (2 * a); printf("root1 = %g + %gi\n", creal(root1), cimag(root1)); printf("root2 = %g + %gi\n", creal(root2), cimag(root2)); return 0; }