Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Issue2;
- var
- n, i: integer;
- A, E, l, r, m, fm, fl, fr, x: double;
- function f(ax: double; mx: integer): double;
- var
- c, b: double;
- begin
- c:= 1;
- b:= ax;
- while mx <> 0 do begin
- if (mx mod 2 = 1) then
- c:= c * b;
- b:= b * b;
- mx:= mx div 2;
- end;
- exit(c);
- end;
- begin
- read(n, A, E);
- if n = 0 then write(1)
- else if A = 0 then write(0)
- else if ((A < 0) and (n mod 2 = 1)) or (A > 0) then begin
- if A < 0 then begin
- i:= -1;
- A:= -A;
- end
- else i:= 1;
- l:= 0;
- if (A > 1)or(A < -1) then r:= A
- else if (A < 1) and(A > 0) then r:= 1
- else r:= -1;
- while (r - l > E) do begin
- m:= l + (r - l) / 2;
- fm:= f(m, n);
- if (fm < a) then begin l:= m; fl:= fm; end
- else begin r:= m; fr:= fm;
- end;
- end;
- if (fl <= a)and(fr >= a) then x:= (l + r)/2;
- write(i*x: 0: 5);
- read(n);
- end
- else write('There is no root of this equation.');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement