#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float root1,root2,a,b,c,d;
clrscr();
printf("\n Quadratic Equation is ax^2=bx+c=0");
printf("\n Enter values of a : ");
scanf("%f",&a);
printf("\n Enter values of b : ");
scanf("%f",&b);
printf("\n Enter values of c : ");
scanf("%f",&c);
d=(b*b)-(4*a*c);
if(d>0)
{
printf("\n Two real and distinct roots ");
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
printf("\n Roots are %f and %f",root1,root2);
}
else
if(d==0)
{
printf("\n Two real and equal roots");
root1=root2=-b/(2*a);
printf("\n Roots are %f and %f",root1,root2);
}
else
printf("\n Roots are COMPLEX and IMAGINARY....!!!");
getch();
}
Output

#include<conio.h>
#include<math.h>
void main()
{
float root1,root2,a,b,c,d;
clrscr();
printf("\n Quadratic Equation is ax^2=bx+c=0");
printf("\n Enter values of a : ");
scanf("%f",&a);
printf("\n Enter values of b : ");
scanf("%f",&b);
printf("\n Enter values of c : ");
scanf("%f",&c);
d=(b*b)-(4*a*c);
if(d>0)
{
printf("\n Two real and distinct roots ");
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
printf("\n Roots are %f and %f",root1,root2);
}
else
if(d==0)
{
printf("\n Two real and equal roots");
root1=root2=-b/(2*a);
printf("\n Roots are %f and %f",root1,root2);
}
else
printf("\n Roots are COMPLEX and IMAGINARY....!!!");
getch();
}
Output
No comments:
Post a Comment