Advertisement
paulogp

Numeros amigos (v. 1.0.1)

Aug 7th, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.63 KB | None | 0 0
  1. { paulogp }
  2. { mac os 7 }
  3. program Ada20p;
  4.  
  5. uses
  6.     MemTypes, QuickDraw, OSIntf;
  7.  
  8. const
  9.     MAX = 300;
  10.  
  11. var
  12.     i, j, k: Integer;
  13.     tecla: string;
  14.     a, b: array[1..MAX] of integer;
  15.  
  16. function somadivisores(X: integer): integer;
  17. var
  18.     limite, soma, i: integer;
  19.  
  20. begin
  21.     limite:= trunc(sqrt(X));
  22.     soma:= 1;
  23.  
  24.     for i:= 2 to limite do
  25.         if (X mod i) = 0 then soma:= soma + i + X div i;
  26.        
  27.     if sqr(limite) = X then somadivisores:= soma - limite else
  28.         somadivisores:= soma; {Caso particular: 16}
  29. end;
  30.  
  31. function amigos(a, b: integer): boolean;
  32. begin
  33.     if a = somadivisores(b) then amigos:= b = somadivisores(a) else
  34.         amigos:= False;
  35. end;
  36.  
  37. procedure Main;
  38. begin
  39.     k:= 1;
  40.     gotoxy(35, 2);
  41.     writeln('Amigos II');
  42.     gotoxy(35, 3);
  43.     writeln('~~~~~~~~~');
  44.     gotoxy(35, 4);
  45.     writeln('Paulo G.P.');
  46.     writeln;
  47.     writeln('Início do cálculo!');
  48.     writeln;
  49.     writeln('Procura no intervalo [0 ,', MAX, ']');
  50.     writeln;
  51.    
  52.     for i:= 2 to MAX - 1 do
  53.     begin
  54.         if (i = 2) then write('|') else
  55.         if i = (MAX - 1) then write('|') else
  56.         if (MAX mod i) = 0 then write('-');
  57.     end;
  58.     writeln;
  59.     for i:= 2 to MAX do
  60.     begin
  61.         if (MAX mod i)=0 then write('|');
  62.         for j:= i+1 to MAX do
  63.         if amigos(i, j) = True then
  64.         begin
  65.             a[k]:= i;
  66.             b[k]:= j;
  67.             k:= k + 1;
  68.         end;
  69.     end;
  70.     writeln;
  71.     writeln;
  72.     writeln;
  73.     writeln('Tabela: ');
  74.     writeln;
  75.     write('I ');
  76.     for i:= 1 to k - 1 do write(a[i],' ');
  77.     writeln;
  78.     write('J ');
  79.     for i:= 1 to k - 1 do write(b[i],' ');
  80.     writeln;
  81. end;
  82.  
  83. begin
  84.     repeat
  85.         clearscreen;
  86.         Main;
  87.         writeln;
  88.         writeln;
  89.         write('Repetir (s/n): ');
  90.         readln(tecla);
  91.         uprstring(tecla, true);
  92.     until tecla = 'N';
  93. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement