开发者

factorial using recursion+pointers [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhet开发者_StackOverfloworical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

i am learning C programming, i was trying to write a recursive function by using this prototype:

void fact(int *n);

The parameter of this function should be passed by reference. Thanks for your help.


I don't feel to be helpful in giving a complete solution -- this is just to show there is an answer:

void fact(int *n)
{
    if (*n > 1)
    {
        int tmp = *n - 1;
        fact(&tmp);
        *n *= tmp;
    }
}

I would never write a factorial function this way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜