Answer the question
In order to leave comments, you need to log in
Why might the below program not work (Pascal)?
There are three numbers 1, 3, 7. Numbers are made up of them in ascending order. For example 1, 3, 7, 11, 13, 17, 31, 33, etc. The position of the number in this sequence is known. For example, position 10 is characterized by the number 71. It is necessary to determine the number itself by the position number. Here is the code:
Program Numbers_Maysen;
var N,k,c,i: integer; s:string; bool:boolean; label 1;
begin
read(N);
c:=0;
k:=0;
repeat
bool:=true;
c:=c+1;
str(c,s);
for i:=1 to length(s) do begin
if pos(s[i], '137') = 0 then bool:=false else k:=k+1;
end;
until k = N;
writeln(c);
end.
Answer the question
In order to leave comments, you need to log in
Try like this:
Program Numbers_Maysen;
var N,k,c,i: integer; s:string; bool:boolean;
begin
read(N);
c:=0;
k:=0;
repeat
bool:=true;
c:=c+1;
str(c,s);
for i:=1 to length(s) do begin
if pos(s[i], '137') = 0 then bool:=false;
end;
if (bool) then k := k + 1;
until k = N;
writeln(c);
end.
if pos(s[i], '137') = 0 then bool:=false;
do it insteadif pos(s[i], '137') = 0 then begin
bool:=false;
break;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question