1. Member
Join Date
Sep 2010
Posts
8
Rep Power
0

## recursive function

can anyone convert this functional paradigm algorithim to a recursive algorithim thanks,

BEGIN program(num1, num2)
declare num3 as integer
WHILE num2 !=0
set num3 to the remainder of num1/num2
set num1 to num2
set num2 to num3
ENDWHILE
RETURN num1
END program

2. Originally Posted by jayden
can anyone convert this functional paradigm algorithim to a recursive algorithim thanks,
Yes I can and I'm sure others can do it too but can you do it? This is not a rent-a-coder forum; you show your attempts and tell us where you are stuck with it.

kind regards,

Jos

3. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
i got as far as writing a recursive function that is extremly simple
BEGIN count(num)
IF num<3
print num
count (n+1)
END IF
END Count
but i cant seem to adapt the aspects of this algorithim into it any help/ pointers would be great

4. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
it would be greatly appreciated if you could step me through the process of changing the algorithim to a recursive function. iam new to software development so please bare with me

5. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
is their anyone who can help me out all i need is two or three lines of code and my problem is solved, please help me out

6. Originally Posted by jayden
can anyone convert this functional paradigm algorithim to a recursive algorithim thanks,

BEGIN program(num1, num2)
declare num3 as integer
WHILE num2 !=0
set num3 to the remainder of num1/num2
set num1 to num2
set num2 to num3
ENDWHILE
RETURN num1
END program
You recursive method should have a structure like this:

Java Code:
BEGIN program(num1, num2)
IF (num2 == 0) RETURN num1
return program( ... , ...)
Notice the recursive call at the end of the function body; you should pass the correct parameter values (those can be found/deduced from the original WHILE body).

kind regards,

Jos

7. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
thank you very much appreciated

8. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
BEGIN program (num1, num2)
declare num3 as int
IF(num2 == 0) RETURN num1
return program(num1/num2) to num3
(num1 to num2)
(num2 to num3)
ENDIF
Return num1
END program

hopefully this will work if not give me one more pointer in the right direction:)
cheers jayden

9. Originally Posted by jayden
BEGIN program (num1, num2)
declare num3 as int
IF(num2 == 0) RETURN num1
return program(num1/num2) to num3
(num1 to num2)
(num2 to num3)
ENDIF
Return num1
END program

hopefully this will work if not give me one more pointer in the right direction:)
cheers jayden
We are talking all pseudo code but I'd rather say it'd be:

Java Code:
BEGIN program(num1, num2)
IF (num2 == 0) RETURN num1
return program( num2, remainder of num1 and num2)
END program
kind regards,

Jos

10. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
what happened to num 3

11. Originally Posted by jayden
what happened to num 3
You want it back? Here it is back again:

Java Code:
BEGIN program(num1, num2)
IF (num2 == 0) RETURN num1
DECLARE num3 as int
num3= remainder of num1 and num2
return program(num2, num3)
END program
kind regards,

Jos

12. Member
Join Date
Sep 2010
Posts
8
Rep Power
0
that you again Jos your efforts are greatly appreciated
cheers Jayden

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•