39. Input any A, B, and C to find the root of the quadratic equation ax * x + bx + c = 0?

Source: Internet
Author: User
// From this question, you can familiarize yourself with the use of the header file # include <cmath> // 1. The question is relatively simple. You only need to use the judgment statement. // 2. Note, when declaring variables, you must think of root irrationality and pay attention to the forced type conversion of function results, SQRT only supports double and float types # include <iostream> # include <cmath> // some common functions such as using namespace STD; int main () {int A, B, C, d; float x1, x2, X3; cout <"Please input a, B and c:" <Endl; CIN> A> B> C; D = B * B-4 * a * C; If (D> 0) {x1 = (-B + (float) SQRT (D)/(2 * )); // when using the root number function, pay attention to forced type conversion X2 = (-B-(float) SQRT (D)/(2 * )); cout <"the equation has two solutions:" <Endl; Cout <"X1 =" <X1 <"X2 =" <X2 <Endl;} else if (D = 0) {cout <"the equation has a solution:" <Endl; X3 = (-B)/(2 * )); the cout <"x =" <X3 <Endl;} else {cout <"equation is not resolved. "<Endl;} return 0 ;}

 

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.