How to resolve the algorithm Mutual recursion step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mutual recursion step by step in the PL/I programming language

Table of Contents

Problem Statement

Two functions are said to be mutually recursive if the first calls the second, and in turn the second calls the first. Write two mutually recursive functions that compute members of the Hofstadter Female and Male sequences defined as:

(If a language does not allow for a solution using mutually recursive functions then state this rather than give a solution by other means).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Mutual recursion step by step in the PL/I programming language

Source code in the pl/i programming language

test: procedure options (main);

M: procedure (n) returns (fixed) recursive;    /* 8/1/2010 */
   declare n fixed;
   if n <= 0 then return (0);
   else return ( n - F(M(n-1)) );
end M;

F: procedure (n) returns (fixed) recursive;
   declare n fixed; 
   if n <= 0 then return (1);
   else return ( n - M(F(n-1)) );
end F;

   declare i fixed;

   do i = 1 to 15;
      put skip list ( F(i), M(i) );
   end;
end test;

  

You may also check:How to resolve the algorithm Horizontal sundial calculations step by step in the Logo programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Bracmat programming language
You may also check:How to resolve the algorithm MD5 step by step in the Suneido programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the dc programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Hy programming language