Reputation: 167
Please tell me where am i wrong, i couldn't fine my mistake in 2 programs. I try to use recursive in pascal.
This one is running but it gives me wrong resuts
program fatorial;
var
n: integer;
function f(n: longint): longint;
begin
if((n=0) or (n=1)) then
f:=1
else
*f:= n*f(n-1);*
read(f);
end;
begin
write('n:='); read(n);
f(n);
write('result:', f(n));
readln;
end.
This one told me "Error: illegal expression" but i don't know how to fix it
program Greatest_common_divisor;
var
gcd,p,q: integer;
r:=real;
begin
write('p:'); read(p);
write('q:'); read(q);
r:= p mod q;
if r <> o then
begin
p:=q;
q:=r
*gcv:= gcv(q,r);*
end;
write('Greatest common divisor:', gcv(p.q));
readln;
end.
Upvotes: 1
Views: 136
Reputation: 27
First question:
f
in the function isn't correct. But the second question:
:=
in the command: r:=real;
, only :
o
and gcv
are what kind of variables? You didn't identify o
and gcv
after var
. ;
after q:=r
Upvotes: 0
Reputation: 739
You should not read f
in the function.
You should write a function rather than use the internal function gcv()
Upvotes: 2