LOVEGUN

Bac2012 (Nombre Circulaire)

Dec 27th, 2020 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.83 KB | None | 0 0
  1. Program PremCirc;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..5] Of Integer;
  5. Var
  6.   f: Text;
  7.   p,q: Integer;
  8.  
  9. Procedure creation (Var f:Text);
  10. Begin
  11.   Assign (f,'C:\bac\Circul.txt');
  12. End;
  13. Procedure saisie (Var p,q:Integer);
  14. Begin
  15.   Repeat
  16.     Writeln ('Saisir p : ');
  17.     Readln (p);
  18.     Writeln('Saisir q: ');
  19.     Readln (q);
  20.   Until (10<p) And (p<q) And (q<20000);
  21. End;
  22. Function circu (x:Integer): Integer;
  23. Var
  24.   i,j,e: Integer;
  25.   ch: String;
  26.   t: Array [1..6] Of Char;
  27. Begin
  28.   Str(x,ch);
  29.   j := 0;
  30.   For i:=2 To Length(ch)+1 Do
  31.     Begin
  32.       j := j+1;
  33.       t[i] := ch[j];
  34.     End;
  35.   t[1] := t[Length(ch)+1];
  36.   For i:=1 To Length(ch) Do
  37.     ch[i] := t[i];
  38.   Val (ch,x,e);
  39.   circu := x;
  40. End;
  41. Procedure circutab (Var t:tab;x:Integer);
  42. Var
  43.   i: Integer;
  44.   ch: String;
  45. Begin
  46.   t[1] := x;
  47.   Str (x,ch);
  48.   For i:=2 To Length(ch) Do
  49.     t[i] := circu(t[i-1]);
  50. End;
  51. Function premier (x:Integer): Boolean;
  52. Var
  53.   i,r: Integer;
  54. Begin
  55.   r := 0;
  56.   For i:=1 To x Do
  57.     If x Mod i = 0 Then r := r+1;
  58.   If r=2 Then premier := True
  59.   Else premier := False
  60. End;
  61. Function primtab (t:tab): Boolean;
  62. Var
  63.   test: Boolean;
  64.   i: Integer;
  65.   ch: String;
  66. Begin
  67.   test := True;
  68.   i := 1;
  69.   Str (t[i],ch);
  70.   While (test) And (i<=Length(ch)) Do
  71.     Begin
  72.       test := premier(t[i]);
  73.       i := i+1;
  74.     End;
  75.   primtab := test;
  76. End;
  77. Procedure traitement (Var f:Text;p,q:Integer);
  78. Var
  79.   i: Integer;
  80.   t: tab;
  81. Begin
  82.   Rewrite (f);
  83.   For i:=p To q Do
  84.     Begin
  85.       circutab(t,i);
  86.       If primtab(t) Then
  87.         Writeln (f,i);
  88.     End;
  89.   Close(f);
  90. End;
  91.  
  92. Procedure affiche (Var f:Text);
  93. Var
  94.   ch: String;
  95. Begin
  96.     reset (f);
  97.     While Not (Eof(f)) Do
  98.     Begin
  99.       Readln (f,ch);
  100.       Writeln (ch);
  101.     End;
  102.         close (f);
  103. End;
  104. Begin
  105.   creation (f);
  106.   saisie (p,q);
  107.   traitement (f,p,q);
  108.   affiche (f);
  109. End.
  110.  
Add Comment
Please, Sign In to add comment