N
N
Nikita Evdokimov2016-10-19 18:35:53
Pascal
Nikita Evdokimov, 2016-10-19 18:35:53

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.

I forgot to indicate that this program at position 10 produces the number 14. And at the fourth position - 10

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-10-19
@nikitae57

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.

Can you if pos(s[i], '137') = 0 then bool:=false;do it instead
if pos(s[i], '137') = 0 then begin
  bool:=false;
  break;
end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question