5 Reputation

One Badge

4 years, 286 days

MaplePrimes Activity

These are questions asked by SYY

Collatz := proc (n)

    local count;

       while n != 1 do

           if `mod`(n, 2) = 0 then n := (1/2)*n

           else n := 3*n+1

           end if;

           count := count+1;

       end do;


end proc:


I wanna correct 'illegal use of formal parameter' error.

'n' always goes to 1 through 'while statement'.

Bubble := proc (X::list)

local n, i, j, t;

n := nops(X);

if n = 0 then ERROR("empty list") end if;

for i to n-1 do

   for j to n-i do

      if X[j+1] < X[j] then

          t := X[j];

          X[j] := X[j+1];

          X[j+1] := t;

      end if;

   end do;

end do;


end proc


I make bubble sort algorithm. but i can't find 'illegal use of a formal parameter'.

Page 1 of 1