N
N
Nikita Evdokimov2016-10-19 17:03:51
css
Nikita Evdokimov, 2016-10-19 17:03:51

Why does a pascal program run indefinitely?

There are three digits: 1, 3, 7. Of these, numbers are made up in ascending order (1, 3, 7, 11, 13, etc.) You need to find the Nth number in a row. Here is the code:
Program Numbers_Maysen;
var N,k,c,i,flag: integer; s:string; label 1;
begin
read(N);
c:=0;
k:=0;
repeat
1: c:= c + 1;
str(c, s);
for i:=1 to length(s) do begin
if pos('1', s[i])=1 then
flag:= 1 else
flag:=0;
if flag = 0 then goto 1 else
if pos('3', s[i])=1 then
flag:= 1 else
flag:=0;
if flag = 0 then goto 1 else
if pos('7', s[i])=1 then
flag:= 1 else
flag:=0;
if flag = 0 then goto 1 else
if flag = 1 then k:=k+1;
end;
until k = N;
writeln(k);
end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2016-10-19
@2ord

Without delving into the code itself, I can advise:

  1. The code needs to be framed with the code tag (in the icon panel on the edge, "..."), updating the message
  2. The program is looping because the exit condition of the loop is not met.
  3. Better get rid of GOTO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question