For the labs task, I decided to, but the conclusion cannot be correctly arranged, please help

The output should be like this: [1; 1,4,4]
The number of output elements may change. This is my main problem.

uses crt; Var n: string; procedure confrac(n:string); Var a,b,c,col,err,zoz: integer; g, h: string; sPos:=1; begin sPos := PosEx('/',n,sPos); g:= Copy(n, 1, spos-1); h:= Copy(n, (sPos+1), length(n)); val(g,a,err); val(h,b,err); while a>1 do begin writeln(a div b); c:=a mod b; a:=b; b:=c; end; end; begin confrac('38/21'); end. 

At the moment I was able to conclude as follows:
one
one
one
four

  • First, replace writeln with write and then print the characters you want (space, bracket, commas). - pavel
  • [1; 1,4,4], and it’s normal that the separator is first ; and then the commas go? - alexoander
  • yes that's the problem - Arbron
  • just in my understanding ; this is a separator between array values. But the comma can be copied in two ways - both as a separator and as a fractional part (although the number with 3 commas is odd) - alexoander
  • @pavel if 1 separator would not be **; ** and then commas, I would have done so - Arbron

1 answer 1

I assume that the solution should look something like this:

 procedure confrac(n: double); Var a, x, eps : double; begin eps := 0.000001; write('['); a := floor(n); x := n - a; write(a, '; '); while x > eps do begin a := floor(1/x); x := 1/x - a; write(a); if x > eps then write(', '); end; writeln(']'); end; begin confrac(38/21); end. 

A source

  • Ошибка времени выполнения: Значение было недопустимо малым или недопустимо большим для Int32. Do you mean it? - Arbron
  • Yes, it is most likely the most. I do not have a pascal compiler to check) - vp_arth
  • Added epsilon, should work - vp_arth
  • right decision thanks - Arbron