Write a C program to calculate the root of a Quadratic Equation.


 

#include <stdio.h> 
#include <conio.h> 
#include <math.h> 
void main() 
    int a, b, c, d; 
    float x1, x2; 
    printf("enter a value of a, b, c: \n"); 
    scanf("%d %d %d", &a, &b, &c); 
    d = b*b-4*a*c; 
    if(d == 0
    { 
        printf("both root are equal \n"); 
        x1 = -b/(2.0*a); 
        x2 = x1; 
        printf("First root root1 = %f\n", x1); 
        printf("Second root root2 = %f\n", x2); 
    } 
    else if(d>0
    { 
        printf("Both root are real and different:  \n"); 
        x1=(-b+sqrt(d))/(2*a); 
        x2=(-b+sqrt(d))/(2*a); 
        printf("First root root1 = %f\n", x1); 
        printf("Second root root2 = %f\n", x2); 
    } 
    else 
    { 
        printf("root are imaginary!\nNo solution."); 
    } 
}


OUTPUT

Enter a value of a, b, c: 

478 

456

123

The root is imaginary!

No solution.


Follow our page for regular updates.

0 Comments