C Program to Find Roots of Quadratic Equation

Write a Program to Find Roots of Quadratic Equation

// C Program to Find Roots of Quadratic Equation

#include <stdio.h>
#include <math.h>

int main()
{
    float a, b, c, delta, root1, root2;
    printf("Enter Coefficient a :--> ");
    scanf("%f", &a);

    printf("Enter Coefficient b :--> ");
    scanf("%f", &b);

    printf("Enter Coefficient c :--> ");
    scanf("%f", &c);

    delta = b * b - 4 * a * c;

    root1 = (-b + sqrt(delta)) / (2 * a);
    root2 = (-b - sqrt(delta)) / (2 * a);
    printf("\nRoot 1 = %.2f", root1);
    printf("\nRoot 2 = %.2f", root2);

    return 0;
}

Output:

Enter Coefficient a :--> 4
Enter Coefficient b :--> 8
Enter Coefficient c :--> 2

Root 1 = -0.29
Root 2 = -1.71

≪ Previous | Next ≫