11/8/2022 0 Comments Turbo pascal a b c![]() ![]() Note that in Turbo Pascal series this program works only with Turbo Pascal 4.0 and higher due to the fact that earlier versions didn’t have char datatype. ![]() String capacity is omitted and thus set to 255 by default. a variable of type PChar is a pointer that points to an array of type Char, which is ended by a null-character (0). ord returns ASCII-code of a character, while chr converts given ASCII-code into a character. The PChar type can be understood best as the Pascal equivalent of a C-style null-terminated string, i.e. ![]() 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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |