This is a discussion on Recursion help please? within the C Programming forums, part of the General Programming Boards category; Hi everyone, I'm a newbie to c programming.... having trouble with recursion now.... how do i write a recursive function ...

Hi everyone,

I'm a newbie to c programming.... having trouble with recursion now....

how do i write a recursive function that prints a positive integer in reversed order? for example: toReversed(345) will display 543.

any tips to attempt doing recursive functions? what are the basic steps to do recursion? any tips for me to write out the algorithm?

thanks everyone!

2. unless this is a homework assignment where you have to use it, recursion isn't the best way to do what you want. It would be worth it to look through the math and string function headers.

3. try a while() loop...

4. Perhaps this gives an impression of what you could do:

345 % 10 = 5
345 - 5 = 340
340 / 10 = 34

34 % 10 = 4
34 - 4 = 30
30 / 10 = 3

5. You may do it this way:

Code:
```//Reverse function
void preversed(int num)
{
int i;

if(num >= 10 )
{
i = num%10;
printf("%d",i);
preversed(num/10);
}
else
printf("%d",num);

}

int main()
{
int num;