Advertisement
paulogp

Metodo de Newton

Aug 7th, 2011
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.83 KB | None | 0 0
  1. {* paulogp *}
  2. {* mac os 7 *}
  3. program Ada28p;
  4.  
  5. uses
  6.     MemTypes, QuickDraw, OSIntf;
  7.  
  8. var
  9.     x, old_guess, new_guess: real;
  10.     tecla: string;
  11.  
  12. begin
  13.     repeat
  14.         clearscreen;
  15.         gotoxy(30, 2);
  16.         writeln('Metodo de Newton');
  17.         gotoxy(30, 3);
  18.         writeln('~~~~~~');
  19.         writeln;
  20.         writeln;
  21.         write('Insira o numero: ');
  22.         readln(x);
  23.         writeln;
  24.         if x > 0.0 then
  25.         begin
  26.             new_guess:= x / 2;
  27.             repeat
  28.                 old_guess:= new_guess;
  29.                 new_guess:= (old_guess + x / old_guess) / 2;
  30.             until new_guess = old_guess;
  31.             writeln('Raiz de ', x: 2, ' e ', new_guess: 3);
  32.         end else
  33.         if x = 0.0 then writeln('Raíz de ', x: 2, ' e ', x: 3) else
  34.             writeln('Este programa funciona apenas com numeros positivos!');
  35.         writeln;
  36.         writeln;
  37.         write('Repetir (s/n): ');
  38.         readln(tecla);
  39.         uprstring(tecla, true);
  40.     until tecla = 'N';
  41. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement