/*Solution of a quadratic equation*/
#include<math.h>
#include<stdio.h>
int main()
{
float a, b, c, d, x1, x2, rp, imp;
/*consider the quadratic equation as ax^2+bx+c=0*/
printf("Enter the values of a:");
scanf("%f", &a);
printf("Enter the values of b:");
scanf("%f", &b);
printf("Enter the values of c:");
scanf("%f", &c);
d=b*b-4*a*c;
printf("\n The value of discriminant is : %f",d);
if(d>=0)
{
printf("\n The root is real");
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("\n The 1st root is: %f", x1);
printf("\n The 2nd root is: %f\n", x2);
}
else
{
printf("\n The root is complex");
rp=-b/(2*a);
imp=sqrt(abs(d))/(2*a);
printf("\n The 1st root is: %f+%fi", rp,imp);
printf("\n The 2nd root is: %f-%fi\n", rp,imp);
}
return(0);
}
#include<math.h>
#include<stdio.h>
int main()
{
float a, b, c, d, x1, x2, rp, imp;
/*consider the quadratic equation as ax^2+bx+c=0*/
printf("Enter the values of a:");
scanf("%f", &a);
printf("Enter the values of b:");
scanf("%f", &b);
printf("Enter the values of c:");
scanf("%f", &c);
d=b*b-4*a*c;
printf("\n The value of discriminant is : %f",d);
if(d>=0)
{
printf("\n The root is real");
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("\n The 1st root is: %f", x1);
printf("\n The 2nd root is: %f\n", x2);
}
else
{
printf("\n The root is complex");
rp=-b/(2*a);
imp=sqrt(abs(d))/(2*a);
printf("\n The 1st root is: %f+%fi", rp,imp);
printf("\n The 2nd root is: %f-%fi\n", rp,imp);
}
return(0);
}
Comments
Post a Comment