LOVEGUN

Bac 2010 8H30

Apr 27th, 2021 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.67 KB | None | 0 0
  1. Program bac20108h30;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..25] Of Integer;
  5. Var
  6.   f: Text;
  7.   ch: String;
  8. Procedure creation (Var f:Text);
  9. Begin
  10.   Assign (f,'c:\bac\nombres.txt');
  11. End;
  12. Procedure remplir (Var f:Text;Var ch1:String);
  13. Var
  14.   n,i: Integer;
  15.   ch: String;
  16. Begin
  17.   Repeat
  18.     Write ('Saisir le nombre d''entiers: ');
  19.     Readln (n);
  20.   Until (2<n) And (n<=50);
  21.   Rewrite (f);
  22.     Randomize;
  23.   For i:=1 To n Do
  24.     Begin
  25.       Str (Random(9)+1,ch);
  26.       Writeln (f,ch);
  27.       ch1 := ch1+ch;
  28.     End;
  29. End;
  30. Function tri (ch:String): String;
  31. Var
  32.   i: Integer;
  33.   ch1,max: String;
  34. Begin
  35.   ch1 := '';
  36.   Repeat
  37.     max := ch[1];
  38.     For i:=1 To Length(ch) Do
  39.       Begin
  40.         If max<ch[i] Then
  41.           max := ch[i];
  42.       End;
  43.     Delete (ch,Pos(max,ch),1);
  44.     ch1 := ch1+max;
  45.   Until (ch='');
  46.   tri := ch1;
  47. End;
  48. Function invers (ch:String): String;
  49. Var
  50.   ch1: String;
  51.   i: Integer;
  52. Begin
  53.   ch1 := '';
  54.   For i:=Length(ch) Downto 1 Do
  55.     ch1 := ch1+ch[i];
  56.   invers := ch1;
  57. End;
  58. Function suite (ch:String): Boolean;
  59. Var
  60.   i,x1,x2,e,r: Integer;
  61.   test: Boolean;
  62.   t: tab;
  63. Begin
  64.  {ch:='7654321'; example de l'exerceice}
  65.   Writeln ('gn: ',tri(ch));
  66.   Writeln ('pn: ',invers(tri(ch)));
  67.   ch := tri(ch);
  68.   For i:=1 To Length(ch) Div 2 Do
  69.     Begin
  70.       Val (ch[i],x1,e);
  71.       Val (ch[Length(ch)-i+1],x2,e);
  72.       t[i] := x1-x2;
  73.     End;
  74.   r := t[1]-t[2];
  75.   i := 1;
  76.   test := True;
  77.   While (test) And (i+1<Length(ch) Div 2) Do
  78.     Begin
  79.       i := i+1;
  80.       test := t[i]-t[i+1]=r;
  81.     End;
  82.   suite := test;
  83. End;
  84. Begin
  85.   creation (f);
  86.   remplir (f,ch);
  87.   If (suite(ch)) Then
  88.     Writeln ('U est une suite arithmetique');
  89. End.
  90.  
Add Comment
Please, Sign In to add comment