``````#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

## All 7 Replies

Becouse d is negative

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!

Becouse d is negative

Solutions of equation 6x^2+5x+4 = 0 are

-0.4167 + 0.7022i
-0.4167 - 0.7022i

Notice "i"!!!!!!

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.