Advertisement
paulogp

Numeros amigos (v. 1.0.0)

Aug 7th, 2011
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.13 KB | None | 0 0
  1. { paulogp }
  2. { mac os 7 }
  3. program Ada19p;
  4.  
  5. uses
  6.     MemTypes, QuickDraw, OSIntf;
  7.  
  8. const
  9.     MAX = 100;
  10.  
  11. var
  12.     k, l: Integer;
  13.     fim: string;
  14.  
  15.  
  16. function amigos(a, b: Integer): Boolean;
  17. var
  18.     I, j, n, soman, somam: integer;
  19.  
  20. begin
  21.     soman:= 0;
  22.     somam:= 0;
  23.    
  24.     for I:= 1 to a - 1 do
  25.         if (a mod I) = 0 then soman:= soman + I;
  26.     for j:= 1 to b - 1 do
  27.         if (b mod j) = 0 then somam:= somam + j;
  28.  
  29.     if (somam = a) and (soman = b) then amigos:= true else amigos:= false;
  30. end;
  31.  
  32. begin
  33.     repeat
  34.         clearscreen;
  35.         gotoxy(33, 2);
  36.         writeln('Programa: Números Amigos!');
  37.         gotoxy(33, 3);
  38.         writeln('~~~~~~~~~~~~~~~~~');
  39.         gotoxy(36, 4);
  40.         writeln('Paulo G.P.');
  41.         writeln;
  42.         writeln('Programa iniciado!');
  43.         writeln('Procura no intervalo [0 ,', MAX, '].');
  44.         writeln;
  45.         for k:= 2 to MAX do
  46.         begin
  47.             if k = MAX / 2 then
  48.             begin
  49.                 writeln;
  50.                 writeln('Meio da contagem!');
  51.                 writeln;
  52.             end;
  53.             for l:= 2 to MAX do
  54.                 if amigos(k, l) then writeln(' São amigos: ', k, ' & ', l);
  55.         end;
  56.         writeln;
  57.         writeln('Terminado!');
  58.         writeln;
  59.         write('Repetir (s/n): ');
  60.         readln(fim);
  61.         uprstring(fim, true);
  62.     until fim = 'N';
  63. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement