Write a program that receives a number of arbitrary length as an input, and at the output gives out a number in direct form and the number vice versa on the next line. Solve the most rational way.

Input example: 7652 Output: 7 6 5 2 2 5 6 7

there is a solution through the lines and without spaces - I can finish them but the task is not for that

program revoptimal; var a:int64; begin readln(a); writeln(a); writeln(ReverseString(inttostr(a))); end. 

    3 answers 3

     // Функция возведения 10 в степень n function Extend(n: integer): integer; var i: integer; r: integer; begin r := 1; for i := 1 to n do r := r * 10; Result := r; end; var x: string; y: integer; z: string; m: integer; i: integer; begin // Читаем введенное число ReadLn(x); // Переводим его в целочисленный тип y := StrToInt(x); WriteLn('input: ', y); z := ''; for i := 0 to Length(x) - 1 do begin // Берем число по модулю 10 от остатка от деления на степень 10 // В виде строки z := z + IntToStr((y Div Extend(i)) Mod 10); // В виде числа m := m + ((y Div Extend(i)) Mod 10) * Extend(Length(x) - (i + 1)); end; WriteLn('output: ', z); WriteLn('output: ', m); end. 

      There may be syntax errors. Long time on it did not write

       function rk(a: integer, d: integer) begin if(a > 0) begin if d = 1 begin Write(a Mod 10) end rk(a Div 10, d); if d = 2 begin Write(a Mod 10) end end end begin rk(7652, 1); WriteLn(''); rk(7652, 2); WriteLn(''); end 

        If you make this program in PascalABC.NET and the input value does not need to be checked, i.e. it is definitely a natural number, then everything can be very simplified:

         begin var S : String; ReadLn(S); foreach var C in S do Print(C); foreach var C in S.ToCharArray.Reverse do Print(C); WriteLn; end. 

        If, nevertheless, it is necessary to use numeric variables without conversions to a string, then you can do this:

         begin var N := ReadLnInteger; var D := 1; while D * 10 < N do D *= 10; repeat Print(N mod (D * 10) div D); D := D div 10; until D = 0; repeat Print(N mod 10); N := N div 10; until N = 0; end.