HKS
HKS

Reputation: 167

i don't know why the program didn't run

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

Answers (2)

Arshia
Arshia

Reputation: 27

First question:

  1. I think reading f in the function isn't correct.

But the second question:

  1. Don't use := in the command: r:=real; , only :
  2. o and gcv are what kind of variables? You didn't identify o and gcv after var .
  3. Put ; after q:=r

Upvotes: 0

TJM
TJM

Reputation: 739

  1. You should not read f in the function.

  2. You should write a function rather than use the internal function gcv()

Upvotes: 2

Related Questions