Answers in C, Python, C++ or Javascript would be very much appreciated. I've read a few books, done all the examples. Now I'd like to write a simple program. But, I already ran into the following roadblock:
My intention is to take an equation from the user and save it in a variable, For example:
-3*X+4 or pow(2,(sin(cos(x))/5)) > [In valid C Math syntax]
And then calculate the given expression for a certain X-Value. Something like this:
printf("%g", UserFunction(3.2)) // Input 3.2 for X in User's Function and Print Result
Any ideas? For the life of me, I can't figure this out. Adding to my frustration, the solution is likely a very simply one. Thank you in advance.
We have 4 ways of solving one-step equations: Adding, Substracting, multiplication and division. If we add the same number to both sides of an equation, both sides will remain equal.
The linear equations in one variable is an equation which is expressed in the form of ax+b = 0, where a and b are two integers, and x is a variable and has only one solution. For example, 2x+3=8 is a linear equation having a single variable in it. Therefore, this equation has only one solution, which is x = 5/2.
There isn't a simple way to do this in C but I think muParser may be useful to you, it is written in C++ but has C binding. ExprTk is also an option but looks like it is C++ only, on the plus side it looks much easier to get interesting results with.
Another option may be the Expression Evaluation which is part of Libav. It is in C and the eval.h header has some good descriptions of the interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With