0
#include<stdio.h>
#include<conio.h>
#include<math.h>

main()
{
float a,b,c,d,k,x,y;
clrscr();
printf("Enetr the values of a,b,c=>");
scanf("%f %f %f",&a,&b,&c);
d=((b*b)-(4*a*c));
k=sqrt(d);
x= (-b+k)/(2*a);
y= (-b-k)/(2*a);
printf("The quadratic equation is x=%f and y=%f",x,y);
getch();
}

but after compiling the result is look like this .....why ....

wnter the values of a,b,c=>6 5 4
sqrt" DOMAIN error
The quadratic equation is x=+NAN and y=+NAN


its the program for to find out the result of the qudratic equation


With regards
Anupam jamatia

5
Contributors
7
Replies
8
Views
10 Years
Discussion Span
Last Post by dwks
Featured Replies
  • 1

    Avoid using non standard headers and non standard functions since it is regarded as bad programming practice. Avoid including [inlinecode] #include <conio.h> [/inlinecode] since it is non standard header and destroys the portability of the program. Same goes with functions [inlinecode] clrscr () [/inlinecode] and [inlinecode] getch () [/inlinecode]. Instead … Read More

0

What about complex solutions of equation?
That is exactly what is happening to you. You entered coefficients so that equation has no real solutions. You need to think about it!

0

Becouse d is negative

What about complex operator?
Solutions of equation 6x^2+5x+4 = 0 are

-0.4167 + 0.7022i
-0.4167 - 0.7022i

Notice "i"!!!!!!

0

What about complex operator?
Solutions of equation 6x^2+5x+4 = 0 are

-0.4167 + 0.7022i
-0.4167 - 0.7022i

Notice "i"!!!!!!

I was refering the NaN problem and occurs becouse d is negative.

#include<stdio.h>
#include<conio.h>
#include<math.h>

main()
{
float a,b,c,d,k,x,y;
clrscr();
printf("Enetr the values of a,b,c=>");
scanf("%f %f %f",&a,&b,&c);
d=((b*b)-(4*a*c));
if (d >= 0)
{
   k=sqrt(d);
   x= (-b+k)/(2*a);
   y= (-b-k)/(2*a);
   printf("The quadratic equation is x=%f and y=%f",x,y);
}
else
{
   float re, im;
   d *= -1;
   k=sqrt(d);
   re = -b/(2*a);
   im = k/(2*a);
   printf("The quadratic equation is x=%f + (%fi)\n", re, im);
   printf("The quadratic equation is y=%f - (%fi)\n", re, im);
}


getch();
}

This is just an idea how to solve complex numbers.
Pozdrav

1

Avoid using non standard headers and non standard functions since it is regarded as bad programming practice.

Avoid including #include <conio.h> since it is non standard header and destroys the portability of the program.

Same goes with functions clrscr () and getch () .

Instead of getch () use getchar () which is a std function.

0

Avoid using non standard headers and non standard functions since it is regarded as bad programming practice.

Avoid including #include <conio.h> since it is non standard header and destroys the portability of the program.

Same goes with functions clrscr () and getch () .

Instead of getch () use getchar () which is a std function.

If your advice was for me just to tell I never use them becouse I compiled with gcc. I added them just becouse original code had them. But anyway thanks for the advice

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.