LOVEGUN

Exercice 2 Bac 2018 (Théo) (Principale)

Apr 13th, 2021 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.65 KB | None | 0 0
  1. Program exrevision;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [0..100] Of Integer;
  5. Var
  6.   n,nt,s: Integer;
  7.  
  8. Procedure fibo (n:Integer;Var nt,s:Integer);
  9. Var
  10.   i,p: Integer;
  11.   t: tab;
  12. Begin
  13.   t[0] := 1;
  14.   t[1] := 1;
  15.   s := 2;
  16.   For i:=2 To n Do
  17.     Begin
  18.       If i Mod 2=0 Then
  19.         Begin
  20.           p := i Div 2;
  21.           t[i] := (t[p-1]*t[p-1])+(t[p]*t[p]);
  22.         End
  23.       Else
  24.         Begin
  25.           p := (i-1) Div 2;
  26.           t[i] := (2*t[p+1]-t[p])*t[p];
  27.         End;
  28.       s := s+t[i];
  29.     End;
  30.   nt := t[n];
  31. End;
  32. Begin
  33.   Writeln ('Saisir N: ');
  34.   Readln (n);
  35.   fibo(n,nt,s);
  36.   Writeln (nt);
  37.   Writeln ('somme: ',s);
  38. End.
  39.  
Add Comment
Please, Sign In to add comment