POWER OPERATOR (**) IN PASCAL PROGRAMMING
In other to write x raised to the power of y in Pascal,
the expression will be x**y, while 5 raised to the power of 2 will be 5**2.
Two asterisks (**) represents power operator in Pascal.
However, the (**) will show error that “method overloading is not created”, as
such, if you want to use the power operator you need to call uses math; above the var keyword. uses math;
is a math library in Pascal, that allows you to access and utilize mathematical
functions.
Lets demonstrate this with simple examples.
Lab1:
//pascal
program to display the result of 5^2 program
lab1; uses
math; begin writeln('The
answer is::'); writeln(5**2); end. |
Lab2:
{
pascal program to display the result of an initialized variable using integer
datatype } program
lab2; uses
math; var a
: integer = 3; b
: integer = 5; begin writeln('The
answer is::'); writeln(a**b); end. |
Lab3:
{
pascal program to display the result of an initialized variable using real
datatype and formatting the output to two decimal places } program
lab3; uses
math; var m
: real = 1.863; n
: real = 2; begin //format
the output to two decimal places writeln('The answer is::'); writeln((m**n)
: 0:2); end. |
Comments
Post a Comment