Write a C program to compute the roots of a quadratic equation . The roots can be calculated using the following formuls

X1=(-b+(b^2 - 4ac))/2a X2=(-b-(b^2-4ac))/2a



Write aprogram that is to prompt the user to enter the constants (a, b, c). Then it should display the roots based on the following rules:

Respuesta :

Answer:

#include <stdio.h>

#include <math.h>

int main()

{

   float a,b,c;

  printf("Enter the value of constants (a,b,c): ");

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

  float x1 = (-b+sqrt(pow(b,2)-4*a*c))/2*a;

  float x2 = (-b-sqrt(pow(b,2)-4*a*c))/2*a;

  printf("The root are x1 = %f and x2 = %f",x1,x2);

}

Explanation:

First include the library stdio.h for input/output and math.h for using the pow(), sqrt() function which is used o find the power and square root values.

pow(2,3) means 3 is the power of 2.

sqrt(4) means square root of 4.

create the main function and declare the variables.

after that, use the formula and calculate the root and store in the variables.

Finally, print the result on the screen.

NOTE:  All variables is float but you can use the integer values as well.