Question:
turbo c: recursive function?
czarrinna
2009-09-21 01:42:28 UTC
can you help me with this.
i can't get it..
use the recursive function pls.

what is the syntax if this is the pattern 2 1 4 3 6 5 8 7
the input is n from 1 to n.

help pls..
Three answers:
Kras
2009-09-21 01:52:26 UTC
I would say, the question is incomplete. I'll provide a brief example with recursion.



Recursive function is a function that calls itself, until it hits the basic/trivial case.

E.g.

factorial(N) = N*factorial(N-1)

factorial(N-1)=(N-1)*factorial(N-2)

and so on

until

factorial(2)=2*factorial(1)

factorial(1)=1

Once we know factorial(1)=1, we go back to find factorial(2), then factorial(3) etc until factorial(N)
Mark aka jack573
2009-09-25 06:04:20 UTC
Here is a recursive function that does what you want.



But, you should make a number where it will stop. Currently I am using 100 for it to stop at. You can change that to whatever you need.



void nameItSomething(int n)

{

if (n == 100)

{

return;

}

printf("%d", n);

if (n % 2 == 0)

{

n = n - 1;

}

else

{

n = n + 3;

}

nameItSomething(n);

}



In your main function you would do something like this to call the function.



nameItSomething(2);



Good luck.
_ENIGMA_
2009-09-21 08:54:50 UTC
when a function's implementation references itself - then that is recursive function. One sample function may be -



int returnFact(int n){

if(n >1) return n*returnFact(n-1);

}



take 2 array of odd and even no and place them in a 3rd array (even-odd) .


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...