Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.97 KB | None | 0 0
  1. program Issue2;
  2. var
  3.   n, i: integer;
  4.   A, E, l, r, m, fm, fl, fr, x: double;
  5. function f(ax: double; mx: integer): double;
  6. var
  7.   c, b: double;
  8. begin
  9.   c:= 1;
  10.   b:= ax;
  11.   while mx <> 0 do begin
  12.     if (mx mod 2 = 1) then
  13.       c:= c * b;
  14.     b:= b * b;
  15.     mx:= mx div 2;
  16.   end;
  17.   exit(c);
  18. end;
  19. begin
  20.   read(n, A, E);
  21.  
  22.   if n = 0 then write(1)
  23.   else if A = 0 then write(0)
  24.   else if ((A < 0) and (n mod 2 = 1)) or (A > 0) then begin
  25.     if A < 0 then begin
  26.       i:= -1;
  27.       A:= -A;
  28.     end
  29.     else i:= 1;
  30.     l:= 0;
  31.     if (A > 1)or(A < -1) then r:= A
  32.     else if (A < 1) and(A > 0) then r:= 1
  33.     else r:= -1;
  34.  
  35.     while (r - l > E) do begin
  36.       m:= l + (r - l) / 2;
  37.       fm:= f(m, n);
  38.       if (fm < a) then begin l:= m; fl:= fm; end
  39.       else begin r:= m; fr:= fm;
  40.       end;
  41.     end;
  42.     if (fl <= a)and(fr >= a) then x:= (l + r)/2;
  43.  
  44.  
  45.     write(i*x: 0: 5);
  46.     read(n);
  47.   end
  48.   else write('There is no root of this equation.');
  49. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement