Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ or c Please no errors Write a program to compute the real roots of a quad

ID: 3672222 • Letter: I

Question

In c++ or c Please no errors Write a program to compute the real roots of a quadratic equation (ax^2 + bx + c = 0). The roots can be calculated using the following formulas: x1 = -b + square of b^2 - 4ac/2a and z2 = - b - square of b^2 - 4ac/2a Your program is to prompt the user to enter the constant (a,b,c), It is then to display the roots based on the following rules: If both a and b are zero, there is no solution. If a is zero, there is only one root (-c/b). IF the discriminate (b^2 - 4ac) is negative, there are no real roots. For all other combinations, there are two roots. Test your program with the data in Table 5 - 13.

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<Math.h>

void main()

{

       int a,b,c,d;

      printf("enter the values of a,b,c");

      scanf("%d%d%d",&a,&b,&c);

    d=((b*b)-(4*a*c));

    if(a==0)

    {

            if(b==0){

                     printf("no solution");

                       }

             else

                  {

                       printf("there is only one root %d",(-c/b));

                   }

}

elseif(d <0 ){

                printf("there are no real roots");

              }

else

{

float x1,x2;

x1=(-b+Math.sqrt(d))/(2*a);

x2=(-b-Math.sqrt(d))/(2*a);

printf("real roots are %f %f",x1,x2);

}

getch();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote