How to get the last digit of a big int in Pascal

1 Answer

0 votes
program LastDigitOfBigInt;

var
  bigIntStr: string;
  lastDigit: Char;

begin
  // Assign the large number as a string literal
  bigIntStr := '123456789123456789123456789123';

  // Validate: check if all characters are digits
  if not (Length(bigIntStr) > 0) then
  begin
    WriteLn('Invalid input. Empty string.');
    Exit;
  end;

  // Get the last character of the string
  lastDigit := bigIntStr[Length(bigIntStr)];

  WriteLn('The last digit of the BigInt is: ', lastDigit);
end.




(*
run:

The last digit of the BigInt is: 3

*)


 



answered Aug 27, 2025 by avibootz

Related questions

1 answer 151 views
1 answer 81 views
1 answer 86 views
1 answer 72 views
1 answer 71 views
1 answer 89 views
...