Header Ads Widget

Write a program to determine the roots of quadratic equation



 Code:-

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,D;
float x1,x2,m;
printf("Enter the coefficient of the each term of the quadratic equation\n");
scanf("%d%d%d",&a,&b,&c);
D=(b*b)-(4*a*c);
if(D<0)
printf("_Imaginary roots\n");
else
{
m=sqrt(D);
x1=(-b+m)/(2*a);
x2=(-b-m)/(2*a);
printf("Roots of the equation are: %f and %f",x1,x2);
}
return 0;
}

Output:-


Enter the coefficient of the each term of the quadratic equation
2 3 1
Roots of the equation are: -0.50000 and -1.000000


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-