Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   What is a recursive function? (http://www.go4expert.com/forums/recursive-function-t1908/)

 desiram 16Nov2006 08:49

What is a recursive function?

Write a program that uses a recursive function to determine if a string is a palindrome

Re: What is a recursive function?

Recursion in computer programming defines a function in terms of itself.A function that calls itself repeatedly, satisfying some condition is called a Recursive Function. Using recursion, we split a complex problem into its single simplest case. The recursive function only knows how to solve that simplest case.

 dhanulakshmi 29Nov2006 10:18

Re: What is a recursive function?

recursive function is nothing but the function calls itself untill the given condition fails...but these recursive functions aren`t that much recomended ,because they will occupy more stack space...i.e genarally when the function is called it occupies one stack frame....when recursive functions are used more more stack sapce is allocated to complete the stack....

code for recursive function to reverse the string ....
strev(char *str)
{
if(*str++!='\0')
{
strev(str);
}
printf("%s",*--str);
}

can u guess what is happening in the above program...as the strev is called recursively....it is occupieing stack frames char by char...as the stack works on LIFO principle....while retriving it prints in reverse order....then u can check..whether the given string and resulted strings are equal are not....if they are equal guven string is palindrome

 Aztec 29Nov2006 17:06

Re: What is a recursive function?

Quote:
 Originally Posted by dhanulakshmi recursive function is nothing but the function calls itself untill the given condition fails...but these recursive functions aren`t that much recomended ,because they will occupy more stack space..
Correct.
Most of the time iterative solution is better than recursive one.

 All times are GMT +5.5. The time now is 13:27.