Turbo pascal programok

broken image
broken image

String capacity is omitted and thus set to 255 by default. ord returns ASCII-code of a character, while chr converts given ASCII-code into a character.

broken image

This example processes the string char by char, and works with ASCII-codes to figure out whether they are lower- or uppercase letters. Program Quadratic var A, B, C, D : integer begin write ( 'A = ' ) readln ( A ) if ( A = 0 ) then begin writeln ( 'Not a quadratic equation.' ) halt end write ( 'B = ' ) readln ( B ) write ( 'C = ' ) readln ( C ) D := B * B - 4 * A * C if ( D = 0 ) then begin writeln ( 'x = ' ,- B / 2.0 / A ) halt end if ( D > 0 ) then begin writeln ( 'x1 = ', ( - B + Sqrt ( D )) / 2.0 / A ) writeln ( 'x2 = ', ( - B - Sqrt ( D )) / 2.0 / A ) end else begin writeln ( 'x1 = (' ,- B / 2.0 / A, ',', Sqrt ( - D ) / 2.0 / A, ')' ) writeln ( 'x2 = (' ,- B / 2.0 / A, ',' ,- Sqrt ( - D ) / 2.0 / A, ')' ) end end.