I like that solution better than the one I suggested.
Don

On Apr 4, 4:45 pm, Dave <[email protected]> wrote:
> @Kumar0746: Technically, you can't solve an _expression_; you can solve an
> _equation_, which is a statement of the form expression = expression, which
> is what you have.
>
> Don's suggestion is a good one. Another way is to call the expression on
> the left side of the equation f(x) and the expression on the right side of
> the equation g(x), and calculate f(0), g(0), f(1), and g(1). Then
>
> x = (f(0) -g(0)) / (f(0) - g(0) - f(1) + g(1))
>
> In the original poster's example, f(0) = 10, f(1) = 8, g(0) = -9, and g(1)
> = 1, so x = 19/12. Presuming that you want the exact answer, leave it in
> fractional form, and if the denominator is negative, then negate both
> numerator and denominator. Then divide both numerator and denominator by
> their gcd. Finally, if the denominator is 1, report the numerator as the
> answer; otherwise report the fraction numerator/denominator as the answer.
>
> Dave
>
>
>
>
>
>
>
> On Thursday, April 4, 2013 11:43:20 AM UTC-5, Don wrote:
> > Simplify the expression by evaluating expressions inside parenthesis
> > first. Follow the order of evaluation, doing multiplications first and
> > then addition and subtraction. It should be possible to reduce any
> > expression to the form
> > ax+b=0. Then x=-b/a.
> > Don
>
> > On Apr 4, 11:18 am, arun kumar <[email protected]> wrote:
> > > Given an expression in the form of a string, solve for x. The highest
> > power
> > > of x in the expression will be equal to 1. Operators allowed are +, *
> > and
> > > -. These are all binary operators. So, 2x would be written as 2*x. Every
> > > operator will be followed by a single term or a constant.
>
> > > For example, consider the following equation:
>
> > > 2*x+5-(4*x-7+(4-2))=10*x-9 Given such an equation, we need to find a
> > > solution to x

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to