Content on the machine: Use the if statement to solve the root of a quadratic equation. Objective: To learn the Branch StructureProgramDesign/** copyright (c) 2012, School of Computer Science, Yantai University * All Rights Reserved. * Prepared by: Yang Chen * Completion Date: July 15, October 25, 2012 * version No.: V1.0 ** enter the value of A, B, and C * Problem description: enter a, B, C to obtain the root of the equation. * Program output: Root of the Output Equation * Problem Analysis :*AlgorithmDESIGN: */# include <iostream> # include <cmath> using namespace STD; int main () {double A, B, C, x1, x2; cout <"Enter the values of A, B, and C:"; CIN> A> B> C; {if (a = 0) {x1 =-C/B; cout <"x =" <X1 <Endl;} else {If (B * B-4 * a * C <0) {cout <"the equation has no solid root. "<Endl;} else {x1 =-B + SQRT (B * B-4 * a * C)/2 *; x2 =-B-SQRT (B * B-4 * a * C)/2 * A; cout <"X1 =" <X1 <Endl; cout <"X2 =" <X2 <Endl ;}} return 0 ;}
Result:
Experience:
Note the application of brackets.