Thread: Need Help with Recursive Function talking in a value and splitting in half

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    2

    Need Help with Recursive Function talking in a value and splitting in half

    Figured this out, thanks.
    Last edited by Atticus89; 10-14-2016 at 09:09 PM.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Dividing by 0.5 is the same as multiplying by 2. Shouldn't you be dividing by 2 (or multiplying by 0.5)?

    And if your base case returns 1 then that's the value that will be recursively divided by 2. Maybe try returning iniV since that's the value that you want to work on.

  3. #3
    Registered User
    Join Date
    Oct 2016
    Posts
    2
    figured it out, thank you though.

    I was returning 1 instead of the initial value for the base case. Also where I was multiplying the 1/2 when the recursive case was being done was outside when it should of been inside the passed parameters.

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    The dividing by two can be in either position, actually, although doing it to the function argument instead of the return value is more efficient since it allows tail recursion.

    The actual problems are as I stated in my first post.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2012, 11:47 AM
  2. Converting recursive function to tail recursive
    By ajacobs365 in forum C Programming
    Replies: 1
    Last Post: 10-30-2011, 08:15 AM
  3. Make Recursive function 'Tail-Recursive'
    By dp2452 in forum C Programming
    Replies: 7
    Last Post: 12-04-2009, 10:13 AM
  4. Replies: 8
    Last Post: 03-31-2006, 08:15 AM
  5. splitting linked list recursive vs. iterative
    By Micko in forum C Programming
    Replies: 7
    Last Post: 03-17-2005, 05:51 PM

Tags for this Thread