#include<stdio.h>
#include<math.h>
int main()
{
  float a,x,y,w,g,s,area,b,c,hg,radius,ho;
   
    printf("enter the value of one side:");
    scanf("%f",&a);
    printf("enter the lengths:");
    scanf("%f%f",&x,&y);
    w=2*x;
    g=2*y;
    s=(a+w+g)/2;
    area=3*sqrt(s*(s-w)*(s-g)*(s-a));
    printf("the area of the triangle is:%f",area);
    b=(2*area)/(3*(w+x));
    c=(2*area)/(3*(g+y));
    
    radius=(a*b*c)/(4*area);
    
    ho=sqrt((9*radius*radius)-(a*a+b*b+c*c));
    
    hg=(2/3)*ho;
    printf("the diatance is:%f",hg);
    
    
    
    
    system("pause");
    return 0;
}

the area comes right but the distance hg shows -1.#IND00 which i think means that the value of points are very very large...can anybody tell me the process of solving this error expect using the BIGFLOAT library

Recommended Answers

All 2 Replies

Try using double, or long double values instead of floating point values. Floats are only 32 bits and hence are quite limited in precision as well as exponent size. Doubles are 64-bits, and I think new compilers that support long doubles allow 128 bit values, which though allowing much larger (and precise) numbers, are much slower to compute as most (or all) current microprocessors will be limited to 64-bit or 80-bit internal floating point operations. Also, remember that precision (the number of decimal places after the integer part of the value) is NOT the scale of the value (the exponent size).

Use signed long double.. This increases the values that can be held by long double by two times (As it doesnt take values less than 0, and in this case, i dont think u require it)

Also, if u want to define the number of decimal places in your output... U can use setw() and set precision(forgot the function for it)

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.