How can i use recusion to get the below number, the number should not in a fixed length....thanks
eg. input 3456
first time get : 3
second time get : 34
third time get : 345
This is a discussion on Recursion problem within the C Programming forums, part of the General Programming Boards category; How can i use recusion to get the below number, the number should not in a fixed length....thanks eg. input ...
How can i use recusion to get the below number, the number should not in a fixed length....thanks
eg. input 3456
first time get : 3
second time get : 34
third time get : 345
Sniff sniff...do i smell homework??
Post what you have written and the people here will help you in fixing your code.
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
below is my code, but it can get the first digit only????thanks
Code:int getFirst(int n) { int rtn; if (n<0) return n; rtn = getFirst(n/10); return rtn; }
That is not going to give you the first digit..n will never be less than 0.
You might want to use a for loop to get one or two or three digits and so on..i would send another variable 'count' along with n to the function telling it to return n when n/(int)pow(10,count) is zero. So, then for your number, it would return 3, then 34, then 345 and then 3456.
count would start with 1 and go on till whatever the number of digits in the number are.
Code:>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.