# Program to find the roots of the quadratic equation with its value

## Code For Program to find the roots of the quadratic equation with its value

``````#include <stdio.h>
#include <conio.h>
#include <math.h>
int main(){
int a, b, c;
float discriminant, root1, root2, rp, ip;
printf("Enter the values of a, b and c: ");
scanf("%d %d %d", &a, &b, &c);

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

root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);

if (discriminant > 0)
{
printf("Roots are real and unequal");
printf("\nroot1 = %.2f and root2 = %.2f", root1, root2);
}

else if (discriminant == 0){
printf("Roots are real and equal");
printf("\nroot1 = root2 = %.2f", root1);
}

else{
printf("Roots are real and imaginary");
rp = -b / (2 * a);
ip = sqrt((4*a*c)-(b*b));
printf("\nReal Part=%f \n Imaginary Part=%f", rp,ip);
}
return 0;
}``````
Output:

Enter the values of a, b and c: 1 3 2
Roots are real and unequal
root1 = -1.00 and root2 = -2.00
Enter the values of a, b and c: 1 2 1
Roots are real and equal
root1 = root2 = -1.00
Enter the values of a, b and c: 1 1 4
Roots are real and imaginary
Real Part=0.000000
Imaginary Part=3.872983