01. /* 02. * copyright (c) 2012, School of Computer Science, Yantai University 03. * All Rights Reserved. 04. * Author: Zhao guanzhe 05. * Completion Date: July 6, October 25, 2012. * version No.: V1.0 07. * input Description: Root 08 Of The unary quadratic equation. * Problem description: Root 09 of a quadratic equation. *ProgramOutput: Two roots of the equation 10. * Problem Analysis: first judge whether it is a quadratic equation, and then judge whether there is a real root 11 .*AlgorithmDESIGN: 12. */13. # include <iostream> # include <cmath> using namespace STD; int main () {float a, B, c, x1, x2; cout <"enter, value of B and C: "; CIN> A> B> C; if (a = 0) {x1 = x2 = (-C)/B; cout <"X1 =" <X1 <Endl; cout <"X2 =" <X2 <Endl ;} else {If (B * B-4 * a * C> = 0) {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;} else {cout <"This equation has no solid root" ;}} return 0 ;}
Running result:
Experience:
This week's task may feel a little difficult, and more people feel that they will not be too much. They should be prepared in a timely manner. Learn more.
Knowledge Point summary:
This task involves the if branch statement. Note the use of parentheses.