sqrt: DOMAIN error

M

manish sahu

int main()
{
float l,c,r,frq;
float u,v;
clrscr();
printf("Enter the value of l r and c");
scanf("%f%f%f",&l,&r,&c);
u=1/(l*c);
v=(r*r)/(4*c*c);
frq=sqrt(u-v);
printf("%f",frq);
getch();
return 0;
}


at run time i m giving value of l, r ,c
5 6 4



this is showing runtime error and printing value
sqrt: DOMAIN error
33.00

plz tell me what is the problem
 
L

luserXtrog

int main()
{
        float l,c,r,frq;
        float u,v;
        clrscr();
        printf("Enter the value of l r and c");
        scanf("%f%f%f",&l,&r,&c);
        u=1/(l*c);
        v=(r*r)/(4*c*c);
        frq=sqrt(u-v);
        printf("%f",frq);
        getch();
        return 0;

}

at run time i m giving value of     l, r ,c
5   6   4

this is showing runtime error and printing value
sqrt: DOMAIN error
33.00

plz tell me what is the problem

sqrt issues a domain error if its argument is less than zero.
Therefore u-v is less than zero and v is greater than u.
But as I don't really know what you're doing,
frq=sqrt(fabs(u-v));
may fix the problem; or it may be nonsense.

hth
 
M

manish sahu

A DOMAIN error is passing a function unacceptable input.
In the case of sqrt(), this is passing a negative number to sqrt().







Do the math.  If v > u, you are passing a negative number to sqrt().
And with those inputs, you are.  Your program should check for this.



plz is a type of currency.  Was this meant as a bribe?

Thank you u are right
 
M

manish sahu

sqrt issues a domain error if its argument is less than zero.
Therefore u-v is less than zero and v is greater than u.
But as I don't really know what you're doing,
        frq=sqrt(fabs(u-v));
may fix the problem; or it may be nonsense.

hth

Thank you u are right
 
N

Nick Keighley

#include <stdio.h>
#include said:
int main()

int main (void)

is better style
{
        float l,c,r,frq;

its more usual to use double rather than float
        float u,v;
        clrscr();

non-standard function
        printf("Enter the value of l r and c");

you should call
fflush (stdout);
to guarantee the output appears
        scanf("%f%f%f",&l,&r,&c);

check that scanf() succeeded. Note scanf()'s error
handling is pretty poor
        u=1/(l*c);
        v=(r*r)/(4*c*c);
        frq=sqrt(u-v);
        printf("%f",frq);
        getch();
        return 0;

}

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top