# Thread: how to compute tan?

1. ## how to compute tan?

Given the function f(x) : 2tanx-x-1=0, write a program that will compute the value for x using trial and error.

Let me explain again, the user inputs a value for x and substitutes it in the formula above. The left side of the equation should equal to 0 once it's computed. If the x entered does not satisfy the equation, then the program should output the correct value for x. My problem is, I can't figure out how to do the tangent in the formula and I can't even find out what x should be.

I'm thinking of placing my code here but I think it's useless anyway cos it's all wrong. I'm using MS Visual C++ to write the code. please help... >_<

wait! i'm not asking you to write the whole program for me but i just want to know how to calculate formulas with tangents in it like the one above. thank you!

2. Code:
#include <math.h>
#include <stdio.h>

void main( void )
{
double pi = 3.1415926535;
double x, y;

x = tan( pi / 4 );
y = tanh( x );
printf( "tan( %f ) = %f\n", pi/4, x );
printf( "tanh( %f ) = %f\n", x, y );
}
... from MSDN.