Assignment 1
//here we have to find out the roots of quadratic equation
#include
#include
#include
int main()
{
float x,y,z,d,r1,r2,r3,r4,r5;
printf("please enter the value of x,y,z = \n ----------------------- \n");
scanf("%f %f %f",&x,&y,&z);//enter values of x y and z
d=(y*y)-(4*x*z);//formula for finding the roots
if(d<0)
{
printf("the roots are complex");
r4=-y/(2*x);
r5=sqrt(-d)/(2*x);
printf(" the roots are %f +i %f \n",r4,r5);
printf("%f - i%f \n",r4,r5);
}
else
if(d==0)
{
printf("the roots are real and equal");
r1=-y/(2*x);
printf("the root is %f",r1);
}
else
{
printf("the roots are real and equal");
r2=(-y+sqrt(d))/(2*x);
r3=(-y-sqrt(d))/(2*x);
printf("the roots are %f %f",r2,r3);
}
getch();
return 0;
}
No comments:
Post a Comment