Week 9 Task 5-find the root of the mona1 quadratic equation

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.