Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.82 KB | None | 0 0
  1. program challenge21;
  2. uses crt;
  3.  
  4. type vetor= array[1..6]of integer;
  5.  
  6. var
  7. show: integer;
  8. vet:vetor;
  9.  
  10. {funcao que verifica o número repetido}
  11. function repetido(v:vetor):integer;
  12. var i,j:integer;
  13.     achou:boolean;
  14. begin
  15.     i:=1;
  16.     j:=2;
  17.     achou:=false;
  18.         while (not achou) and (i<=6) and (j<=6) do
  19.         begin
  20.              if v[i]=v[j] then
  21.                 achou:=true
  22.             else
  23.                 j:=j+1;
  24.             if j=7 then
  25.             begin
  26.                 i:=i+1;
  27.                 j:=i+j;
  28.             end;
  29.         end;   
  30.     if achou then
  31.         repetido:=v[i]
  32.     else
  33.         repetido:=-1;
  34. end;
  35. {inicio do programa principal}
  36. BEGIN
  37.     vet[1]:=1;
  38.     vet[2]:=2;
  39.     vet[3]:=3;
  40.     vet[4]:=4;
  41.     vet[5]:=1;
  42.     vet[6]:=5;
  43.     clrscr;
  44.     show:=repetido(vet);
  45.     textcolor(red);
  46.     gotoxy(25,10);
  47.     if show<>-1 then
  48.         writeln('O Número Repetido do Vetor é ',show)
  49.     else
  50.         writeln('Nao ha numeros repetidos');
  51.     readln;
  52. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement