Recursion...help,tips,suggestions
hi there I need some serious help with recursions! i have read the tutorial on this site i am reading some info out of a book and i still find it hard to understand!
if you have any tip or suggestions on how you understand recursion can you pleas post here so i can look at it.. also if you know any links of good explanations i would like to look at the also!
thanks in advance!
i defintlay understand it now..
however i need to figure out how to problem solve with it! anyhelp would be greatly appreciated! here is a question im working on! my coding is wrong which ill show you if you could push me in the right direction and tell me if what im doing is rightish or wrongish that would be great! this Site has helped me so much! i hope one day to become a very regular and contributing member!
okay.. here goes nothing!
Question: One way to count the number of digits in a positive number is to use a recursive function -digits-. The number is passed as an argument to the function. The function returns the value 1 is the number is less than 10, otherwise it returns 1+the number of digits in the number when divided by 10. write the recursive function in C, then write a non-recursive version of the same function.
now.. im going to show you my attempt.. its not very good.. but its the best i could do lol.. the code isnt even working.. can you please exapline to me why etc.. im not looking for an answer im just looking for explinations if that makes any sense.. lol
Code:
int main(){
int digits (/*i dont know how to give digit function a number for its argument*/){
if (digits > 9 ){
return 1;
}else{
return 1+(digits/10);/*not sure this is even close..but this is the recursive bit.. i think*/
}
}
thanks for all the help so far! its really helped!
okay.. i fully understand recursion now..
maybe its this question thats trowing me off!
How the heck would i make recursive code outta that question?
i know how to make it non recursive.. thats easly done! but Recursive.. dose anyone have any idea how it could be done?
please explain:)