program latihan;
uses crt;
var
a, b, c : integer;
d : real;
begin
write('a: ');
readln(a);
write('b: ');
readln(b);
c := a + b;
d := a + b;
sqr(c);
writeln(c);
sqrt(d);
writeln(d:0:0);
end.
why there's an illegal expression at code sqrt(d) ??
what is the explanation why there can be an illegal expression at the sqrt(d) code and how to fix it?
The sqrt() function in Pascal only works on integer types, while d is a real type. So trying to pass a real value to sqrt() results in an illegal expression error.
To fix this, you need to use a different square root function that supports real numbers, such as:
Alternatively, you can convert d to an integer first before using sqrt():