Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program bac2020;
- Uses Wincrt;
- Var
- f1,f13,f7: Text;
- Procedure remplir (Var f1:Text);
- Var
- nb,i: Integer;
- n:string;
- Begin
- Repeat
- Writeln ('Saisir NB: ');
- Readln (nb);
- Until (nb>=1);
- Rewrite (f1);
- For i:=1 To nb Do
- Begin
- Readln (n);
- Writeln (f1,n);
- End;
- Close (f1);
- End;
- Function divis13 (n:String): Boolean;
- Var
- sg,s,e,v: Integer;
- Begin
- s := 0;
- sg := -1;
- While Length(n)>=3 Do
- Begin
- Val (Copy(n,Length(n)-2,3),v,e);
- s := s+v*sg;
- sg := -sg;
- Delete (n,Length(n)-2,3);
- End;
- Val (n,v,e);
- s := s+v*sg;
- divis13 := Abs(s) Mod 13=0;
- End;
- Function divis7 (n:String): Boolean;
- Var
- sg,p,e,s,x,i:integer;
- ch:string;
- Begin
- ch := '132';
- sg := 1;
- While Length(n)>=2 Do
- Begin
- i := 0;
- s := 0;
- Repeat
- i := i+1;
- Val (n[Length(n)],x,e);
- Val (ch[i],p,e);
- s := s+x*p*sg;
- Delete (n,Length(n),1);
- If (i=3) Then
- Begin
- i := 0;
- sg := -sg;
- End;
- Until (n='');
- Str (abs(s),n);
- End;
- divis7:=(n='7') or (n='0');
- End;
- Procedure traitement (Var f1,f13,f7:Text);
- Var
- n: string;
- Begin
- Reset (f1);
- Rewrite (f7);
- Rewrite (f13);
- While Not (Eof(f1)) Do
- Begin
- Readln (f1,n);
- If divis7 (n) Then
- Writeln (f7,n);
- If divis13 (n) Then
- Writeln (f13,n);
- End;
- Close (f1);
- Close (f7);
- Close (f13);
- End;
- Begin
- Assign (f1,'c:\bac\Nombres.txt');
- Assign (f13,'c:\bac\divis13.txt');
- Assign (f7,'c:\bac\divis7.txt');
- remplir (f1);
- traitement (f1,f13,f7);
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement