--- In [email protected], "Paul Herring" <[EMAIL PROTECTED]> wrote:
>
> On Thu, Apr 3, 2008 at 10:12 AM, mdnizdil <[EMAIL PROTECTED]> wrote:
> >  Please help me. In this question  a,b,c are legs of the
> >  triangle. And I want to find area of the triangle.
> >
> >        s=(a+b+c)/2
> >        Area=s*((s-a)(s-b)(s-c)) ^ (1/2)
> >
> >  I wrote the programme, could you please correct my programme.
> >
> [...]
> >   area=sqrt(pow(s*(s-a)(s-b)(s-c)),1/2);
> 
> 1) That closing parens is in the wrong place.
> 
> 2) 1/2 in this expression resolves to 0 (since you're
> inplicitly using integer arithmetic instead of floating
> point.) Use either 1.0/2 or 0.5 instead to get '1/2'
> 
> 3) You're using sqrt() to get a root and appear to be trying
> to use pow() to get another root, why not just get the 4th
> root by using pow(..., 1.0/4) and remove the sqrt() call?

Furthermore the syntax for multiplication is correct in mathematical
circumstances, but in C the OP has to use the multiplication operator
explicitly under all circumstances, meaning that the expression should
read:
  area = sqrt( s * (s - a) * (s - b) * (s - c));
or, as Paul pointed out:
  area = pow( s * (s - a) * (s - b) * (s - c), 0.5);

Regards,
Nico

Reply via email to