Results 1 to 2 of 2

Thread: program(roots of quadratic equation)

  1. #1
    IqraIqbal's Avatar
    IqraIqbal is offline Advance Member
    Last Online
    24th June 2021 @ 10:05 AM
    Join Date
    16 Jun 2014
    Location
    bahawalpur
    Age
    32
    Gender
    Female
    Posts
    1,846
    Threads
    78
    Credits
    400
    Thanked
    258

    Default program(roots of quadratic equation)



    quadratic equation
    ax^2 +bx +c =0
    quadratic formula

    program to find the roots of quadratic equation.
    program
    #include <iostream.h>
    #include <conio.h>
    #include<math.h>
    int main()
    {
    float a, b, c, x1, x2, determinant, realPart, imaginaryPart;
    cout << "Enter coefficients a, b and c";
    cin >> a >> b >> c;
    determinant = b*b - 4*a*c;

    if (determinant > 0)
    {
    x1 = (-b + sqrt(determinant)) / (2*a);
    x2 = (-b - sqrt(determinant)) / (2*a);
    cout << "Roots are real and different." << endl;
    cout << "x1 = " << x1 << endl;
    cout << "x2 = " << x2 << endl;
    }

    else if (determinant == 0)
    {
    cout << "Roots are real and same." << endl;
    x1 = (-b + sqrt(determinant)) / (2*a);
    cout << "x1 = x2 =" << x1 << endl;
    }

    else {
    realPart = -b/(2*a);
    imaginaryPart =sqrt(-determinant)/(2*a);
    cout << "Roots are complex and different." << endl;
    cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
    cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
    }
    getch();
    return 0;
    }

  2. #2
    xio.zed is offline Member
    Last Online
    31st October 2015 @ 02:37 AM
    Join Date
    10 Aug 2014
    Location
    Faisalabad
    Age
    28
    Gender
    Male
    Posts
    67
    Threads
    10
    Thanked
    4

    Default

    Awexome dude.. (y) ^_^

Similar Threads

  1. Quadratic Equation
    By safiullahjan in forum Ask an Expert
    Replies: 1
    Last Post: 19th September 2013, 10:48 AM
  2. quadratic equation coding for c++
    By safiullahjan in forum Ask an Expert
    Replies: 0
    Last Post: 16th September 2013, 04:05 PM
  3. Maths paper banan with equation?
    By marifkhan2006 in forum General Discussion
    Replies: 1
    Last Post: 26th February 2011, 10:57 AM
  4. Solve Quadratic Equation using c language
    By ehmad in forum General Discussion
    Replies: 1
    Last Post: 17th October 2008, 09:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •