Advertisement
shchuko

Ord()&Chr() on Pascal

May 27th, 2018
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.88 KB | None | 0 0
  1. var
  2.     ch1, ch2, ch3: char;
  3.     int1, int2, int3: integer;
  4. begin
  5.     write('Enter a random character: ');
  6.     readln(ch1);    {reading character}
  7.  
  8.     int1 := Ord(ch1);   {character --> character's integer number}
  9.     writeln('You entered character: ', ch1, '. Number of this character: ', int1);
  10.  
  11.     writeln('---------------');
  12.  
  13.     write('Enter a random number (0..255): ');
  14.     readln(int2);   {reading integer}
  15.  
  16.     ch2 := Chr(int2);   {character's integer number --> character}
  17.     writeln('You entered number: ', int2, '. The character on this number: ', ch2);
  18.    
  19.     writeln('---------------');
  20.    
  21.     write('Enter a random digit (0..9): ');
  22.     readln(ch3);    {reading digit as character}
  23.    
  24.     int3 := Ord(ch3) - Ord('0'); {converting char digit --> integer digit}
  25.     writeln('You entered digit, char: ', ch3, ', integer: ', int3);
  26.  
  27.     writeln('---------------------------');
  28.     writeln('Press any key...');
  29.     readln;
  30. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement