Mathematical expressions in Pascal: Abs, Exp, Power

functions

How to write it in pascal? And is it correct:

a1 <> (1,78 * (sqr(10) * 10) / c2 + c3
(15,22 b) + (1 / (0,5 y))
exp(x - 1) * (abs(sqr(x)) + power(x, 1 / 3)
Author: Ainar-G, 2020-06-03

2 answers

You have several errors in the code, the main ones are the use of a comma as a decimal separator (in pascal it is a period) and implicit multiplication (not in pascal). Also, you didn't specify the Pascal dialect. Here is a program without initializing variables in dialect Free Pascal:

PROGRAM Main;

USES
    Math;

VAR
    a1, b, c2, c3, g, x: Real;

BEGIN
    { TODO(you):  Initialise all variables.  }

    WriteLn(a1 <> (1.78 * Math.Power(10, 3)) / (c2 + c3));
    WriteLn(15.22 * b + 1 / (0.5 * g));
    WriteLn(Exp(x - 1) * Abs(Sqr(x)) + Math.Power(x, 1 / 3));
END.
 1
Author: Ainar-G, 2020-06-03 17:07:09

Here you need parentheses in the denominator and the number is better simply written in scientific notation with a dot instead of a comma

a1 <> 1.78Е3 / (c2 + c3)

There are no signs here and they forgot about the denominator again

15.22*b +  1 / (0.5*gamma)

The latter is true (abs is superfluous for a square, but since it is in the record...)

 1
Author: MBo, 2020-06-03 17:08:56