Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program bac2011;
- Uses Wincrt;
- Type
- nombre = Record
- Nb_dc: Longint;
- mention: String;
- End;
- tab = Array [1..50] Of nombre;
- Var
- f: Text;
- t: tab;
- Procedure creation (Var f:Text);
- Begin
- Assign (f,'C:/bac/chaines.txt');
- End;
- Function verif (ch:String): Boolean;
- Var
- test: Boolean;
- i: Integer;
- Begin
- i := 0;
- Repeat
- i := i+1;
- test := ch[i] In ['A'..'Z','a'..'z','0'..'9',' '];
- Until (test=False) Or (i=Length(ch));
- verif := test;
- End;
- Procedure remplir (Var f:Text);
- Var
- i,n: Integer;
- ch: String;
- Begin
- Rewrite (f);
- Repeat
- Write ('Saisir N: ');
- Readln (n);
- Until n<50;
- For i:=1 To n Do
- Begin
- Repeat
- Write ('Saisir la chaine ',i,' : ');
- Readln (ch);
- Until (verif(ch)) And (Length(ch)<=9);
- Writeln (f,ch);
- End;
- Close (f);
- End;
- Function decimal (ch:String): Longint;
- Var
- i,e,x: Integer;
- ch1: String;
- Begin
- Repeat
- Val (ch,x,e);
- If e>0 Then
- Delete (ch,e,1);
- If ch='' Then
- Begin
- x := 199999999;
- e := 0;
- End;
- Until e=0;
- decimal := x;
- End;
- Function divis (n:Longint): String;
- Var
- Simpair,Spair,i,x,e: Integer;
- ch: String;
- Begin
- If n=199999999 Then
- divis := 'Ce n''est pas un nombre décimal'
- Else
- Begin
- Str (n,ch);
- Spair := 0;
- Simpair := 0;
- For i:=1 To Length (ch) Do
- Begin
- Val (ch[i],x,e);
- If x Mod 2 = 0 Then
- Spair := Spair+x
- Else
- Simpair := Simpair+x;
- End;
- If Abs(Spair-Simpair) Mod 11=0 Then
- divis := 'est divisible par 11'
- Else divis := 'n''est pas divisble par 11';
- End;
- End;
- Procedure traitement (Var f:Text;Var t:tab);
- Var
- i,j: Integer;
- ch: String;
- Begin
- Reset (f);
- i := 0;
- While Not (Eof(f)) Do
- Begin
- i := i+1;
- Readln (f,ch);
- t[i].Nb_dc := decimal (ch);
- t[i].mention := divis(t[i].Nb_dc);
- End;
- Close (f);
- For j:=1 To i Do
- Begin
- Writeln ('Nb_Dec ',j,' : ',t[i].Nb_dc,' ',t[i].mention);
- Writeln ('-----------------------------');
- End;
- End;
- Begin
- creation (f);
- remplir (f);
- traitement (f,t);
- End.
Advertisement
Add Comment
Please, Sign In to add comment