# How to write a solution to the equation?

``|x| + 2*A = 0.` `

Given the equation. Variable A we set in input.txt . Let it be -1. Decisions will be 2: 2 and -2. I know how to solve it, but the question is - I don’t know how to put it into the program. In output.txt there should be this. In the first line of the output file output the number of solutions of this equation, and in the second line, the solutions themselves should be separated with a space.

In general, I assigned a variable

` `у:=2*A` `

and then

` `Z:=|x|*y` `

But the latter is wrong. Tell me how to write to the program in ouput wrote the number of decisions and solutions. And how to make an equation.

And by the way, here's the solution

` `|x|+2*-1=0;` `

`|x|-2=0;` I'm interested in how to write this line in the program.

` `x=2; x=-2;` `
• The text of the eye cuts. It is not necessary to do everything in a slant. - teanYCH

The task is not as simple as it seems at first glance. True, if the equation is always the same, then everything is much simpler.

Easy way (the number of equations is limited)

` `var equation: string; //...здесь считываем из файла параметр А read(equation); case equation of "|x| + 2*A = 0": begin Z1 := -2*A; Z2 := -(-2*A); amount:=2; if Z1=Z2 then begin amount := 1; end; end; "x^2 - 8*A*A = 0": begin Z1 := sqrt(8)*A; Z2 := -sqrt(8)*A; amount:=2; if Z1=Z2 then begin amount := 1; end; end; //...И так далее для каждого end;` `

Difficult way: (If the equation is set, for example, by the teacher) Honestly - too lazy to write. = (Dig in the direction of the reverse Polish notation , respectively, of stacks and recursion. You need to consistently run through the example (character by line), opening all the brackets and taking into account the priority of the signs of arithmetic.

Express `x` through `A` on a piece of paper. And write the same thing in Pascal.

1. If A <0. then there are two solutions: + 2A and -2A.
2. If A = 0. then the solution is one, and this is zero.
3. If A> 0. then there is no solution.