Program S3;
Var
ch : string[15];
som : integer;
//**************************************
Function verif(ch:String) : boolean;
Var
ok : boolean;
i : integer;
Begin
ok := true;
i := 1;
While (ok) And(i<=length(ch)) Do
If (ch[i] In ['0'..'9']) Then
i := i+1
Else
ok := false;
verif := ok;
End;
//**************************************
Function somme(ch:String) : integer;
Type
tab = array[1..15] Of integer;
Var
s,i,v,e : integer;
t : tab;
Begin
For i:=1 To length(ch) Do
Begin
val(ch[i],v,e);
If (i Mod 2 =0) Then
t[i] := 2*v
Else
t[i] := v;
End;
s := 0;
For i:= 1 To length(ch) Do
If (t[i]<10) Then
s := s+t[i]
Else
s := s+(t[i] Mod 10)+(t[i] Div 10);
somme := s;
End;
//**************************************
Begin
Repeat
write('saisir un N° de 15 chiffres: ');
readln(ch);
Until (length(ch)=15) And (verif(ch));
som := somme(ch);
writeln;
writeln('------------------------------------------------------------');
writeln;
If (som Mod 10=0) Then
writeln(ch,' est un IMEI!!')
Else
writeln(ch,' n''est pas IMEI!!!');
End.
Inscription à :
Publier les commentaires (Atom)