code to solve 3 degree equations even if roots are imaginary it shows the value

0 votes
asked Nov 20, 2019 by abhishek bhaware

1 Answer

0 votes
answered Feb 28 by Lingesh R A (190 points)
#include <stdio.h>
#include<math.h>

void main()
{
float a,b,c,x,x1;
float m,m1;
printf("enter values of a b and c");
scanf("%f %f %f",&a,&b,&c);
if((b*b)<(4*a*c))
{
    m=(-1)*((b*b)-(4*a*c));
    m1=sqrt(m);
    b=-b/(2*a);
    m=m1/(2*a);
    printf("  %f+i%f  ",b,m);
    printf("  %f-i%f ",b,m);
}
else
{
x=((-b)+sqrt((b*b)-(4*a*c)))/(2*a);
x1=((-b)-sqrt((b*b)-(4*a*c)))/(2*a);
}
printf("  %f  ",x);
printf("  %f  ",x1);

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...