It calculates the roots of a quadratic equation. Coefficients are assumed to be integers, but roots may or may not be real. For a quadratic equation ax2+ bx + c = 0 (a≠0), discriminant (b2-4ac) decides the nature of roots. If it's less than zero, the roots are imaginary if it's greater than zero roots are real. If it's zero, the roots are equal. For a quadratic equation sum of its roots = -b/a and product of its roots = c/a.
QUADRATIC EQUATION
#include<stdio.h>#include<conio.h>
#include<math.h>
void main()
{
inta,b,c,d;
float real,imag,r1,r2;
clrscr();
printf("\n\t\tQUADRATIC EQUATION");
printf("\n\n Enter the values of a,b,c:");
scanf("%d%d%d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d>0)
{
printf("\n real and disc roots");
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\n root1=%.2f",r1);
printf("\n root2=%.2f",r2);
}
else if(d==0)
{
printf("\n Roots are Equal");
r1=-b/(2*a);
r2=r1;
printf("\n root1= %.2f",r1);
printf("\n root2= %.2f", r2);
}
else if(d<0)
{
printf("\n Roots are Complex ");
real=-b/(2*a);
imag=sqrt(-d)/(2*a);
printf("\nroot1= %.2f+%.2fi \t root2= %.2f-%.2fi",real,imag,real,imag);
}
getch();
}
OUTPUT:
Eg 1:
Eg 2:
Eg 3:
BY
REGU RAM SV.
Post a Comment