Advertisement
LOVEGUN

Exercice 5 (Série #4) (Classe)

Apr 13th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.76 KB | None | 0 0
  1. Program ex5;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..40] Of Integer;
  5. Var
  6.   t,v: tab;
  7.   i,n,x,u: Integer;
  8.  
  9. Function position (x:Integer;t:tab;n:Integer): Integer;
  10. Var
  11.   i: Integer;
  12. Begin
  13.   For i:=1 To n Do
  14.     If t[i]=x Then
  15.       position := 1;
  16. End;
  17. Begin
  18.   Repeat
  19.     Writeln ('Saisir N: ');
  20.     Readln (n);
  21.   Until n In [5..40];
  22.   For i:=1 To n Do
  23.     Repeat
  24.       Write ('T[',i,']: ');
  25.       Readln (t[i]);
  26.     Until (t[i]>0);
  27.   u := 1;
  28.   x := 0;
  29.   For i:=1 To n Do
  30.     Begin
  31.       u := 3*u-1;
  32.       If position (3*u-1,t,n)<>0 Then
  33.         Begin
  34.           x := x+1;
  35.           v[x] := t[i];
  36.         End;
  37.     End;
  38.   If x=0 Then
  39.     Writeln ('Aucun élément correspend à la suite')
  40.   Else
  41.     For i:=1 To x Do
  42.       Writeln (v[i]);
  43. End.
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement