Pure Programmer
Blue Matrix


Cluster Map

Project: Cubic Roots

Cubic equations of the form Ax3 + Bx2 + Cx + D = 0 have three possible solutions given by the [[Cubic Formula]]. Write a program that sets the constants A = 1, B = -6, C = 11 and D = -6 then prints the three possible solutions. Then change the constants A, B, C and D to get solutions to other quadratic equations. Is it possible that this program could fail?

Output
$ g++ -std=c++17 CubicRoots.cpp -o CubicRoots -lfmt $ ./CubicRoots root #1: 3 root #2: 2 root #3: 1

Solution