How to get the absolute value of a number in Pascal

1 Answer

0 votes
program AbsoluteValueExample;

var
  intNum: Integer;
  realNum: Real;

begin
  // Example with integer
  intNum := -48915;
  writeln('The absolute value of ', intNum, ' is ', Abs(intNum));

  // Example with real number
  realNum := -3.14159;
  writeln('The absolute value of ', realNum:0:5, ' is ', Abs(realNum):0:5);
end.




(*
run:

The absolute value of 16621 is 16621
The absolute value of -3.14159 is 3.14159

*)





 



answered Dec 5, 2025 by avibootz
...