LOVEGUN

Bac 2011 #3

Feb 12th, 2021 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.23 KB | None | 0 0
  1. Program bac2011;
  2. Uses Wincrt;
  3. Type
  4.   nombre = Record
  5.     Nb_dc: Longint;
  6.     mention: String;
  7.   End;
  8.   tab = Array [1..50] Of nombre;
  9. Var
  10.   f: Text;
  11.   t: tab;
  12.  
  13. Procedure creation (Var f:Text);
  14. Begin
  15.   Assign (f,'C:/bac/chaines.txt');
  16. End;
  17.  
  18. Function verif (ch:String): Boolean;
  19. Var
  20.   test: Boolean;
  21.   i: Integer;
  22. Begin
  23.   i := 0;
  24.   Repeat
  25.     i := i+1;
  26.     test := ch[i] In ['A'..'Z','a'..'z','0'..'9',' '];
  27.   Until (test=False) Or (i=Length(ch));
  28.   verif := test;
  29. End;
  30.  
  31. Procedure remplir (Var f:Text);
  32. Var
  33.   i,n: Integer;
  34.   ch: String;
  35. Begin
  36.   Rewrite (f);
  37.   Repeat
  38.     Write ('Saisir N: ');
  39.     Readln (n);
  40.   Until n<50;
  41.   For i:=1 To n Do
  42.     Begin
  43.       Repeat
  44.         Write ('Saisir la chaine ',i,' : ');
  45.         Readln (ch);
  46.       Until (verif(ch)) And (Length(ch)<=9);
  47.       Writeln (f,ch);
  48.     End;
  49.   Close (f);
  50. End;
  51.  
  52. Function decimal (ch:String): Longint;
  53. Var
  54.   i,e,x: Integer;
  55.   ch1: String;
  56. Begin
  57.   Repeat
  58.     Val (ch,x,e);
  59.     If e>0 Then
  60.       Delete (ch,e,1);
  61.     If ch='' Then
  62.       Begin
  63.         x := 199999999;
  64.         e := 0;
  65.       End;
  66.   Until e=0;
  67.   decimal := x;
  68. End;
  69.  
  70. Function divis (n:Longint): String;
  71. Var
  72.   Simpair,Spair,i,x,e: Integer;
  73.   ch: String;
  74. Begin
  75.   If n=199999999 Then
  76.     divis := 'Ce n''est pas un nombre décimal'
  77.   Else
  78.     Begin
  79.       Str (n,ch);
  80.       Spair := 0;
  81.       Simpair := 0;
  82.       For i:=1 To Length (ch) Do
  83.         Begin
  84.           Val (ch[i],x,e);
  85.           If x Mod 2 = 0 Then
  86.             Spair := Spair+x
  87.           Else
  88.             Simpair := Simpair+x;
  89.         End;
  90.       If Abs(Spair-Simpair) Mod 11=0 Then
  91.         divis := 'est divisible par 11'
  92.       Else divis := 'n''est pas divisble par 11';
  93.     End;
  94. End;
  95.  
  96. Procedure traitement (Var f:Text;Var t:tab);
  97. Var
  98.   i,j: Integer;
  99.   ch: String;
  100. Begin
  101.   Reset (f);
  102.   i := 0;
  103.   While Not (Eof(f)) Do
  104.     Begin
  105.       i := i+1;
  106.       Readln (f,ch);
  107.       t[i].Nb_dc := decimal (ch);
  108.       t[i].mention := divis(t[i].Nb_dc);
  109.     End;
  110.   Close (f);
  111.   For j:=1 To i Do
  112.     Begin
  113.       Writeln ('Nb_Dec ',j,' : ',t[i].Nb_dc,' ',t[i].mention);
  114.       Writeln ('-----------------------------');
  115.     End;
  116. End;
  117. Begin
  118.   creation (f);
  119.   remplir (f);
  120.   traitement (f,t);
  121. End.
  122.  
Advertisement
Add Comment
Please, Sign In to add comment