i keep getting sqrt DOMAIn error during runtym.how to reslov

February 27, 2013 at 05:23:02
Specs: Windows 7
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
clrscr();
float a,b,c;
float d,e,y,z,p,x1,x2;
printf("\nEnter tha value of a:");
scanf("%d",&a);
printf("\nEnter tha value of b:");
scanf("%d",&b);
printf("\nEnter tha value of c:");
scanf("%d",&c);
d=pow(b,2);
e=2*a;
y=4*a*c;
z=d-y;
p=sqrt(z);
x1=(-b+p)/(e);
x2=(-b-p)/(e);
printf("\n First root of quadratic equation=%f",x1);
printf("\n Second root of quadratic equation=%f",x2);
getch();
}

See More: i keep getting sqrt DOMAIn error during runtym.how to reslov

Report •


#1
February 27, 2013 at 05:45:49
Enter tha value of a:2

Enter tha value of b:5

Enter tha value of c:3

 First root of quadratic equation=-1.250000
 Second root of quadratic equation=-1.250000

It compiles and runs for me. Have you tried a complier updated since you were born?

How To Ask Questions The Smart Way


Report •

#2
February 27, 2013 at 07:38:12
But you can easily pick values of a, b, and c that would give that error (1, 0, 1 for example). You really need to check that z is not negative; otherwise there are no real solutions to the equation. A good program would solve all cases by producing complex answers too.

Report •

Related Solutions


Ask Question