Ask Experts Questions for FREE Help !
Ask
    prashant kumar's Avatar
    prashant kumar Posts: 2, Reputation: 1
    New Member
     
    #1

    Oct 16, 2008, 07:14 AM
    Recusion function
    Write the recursion function to print the factoial of a number
    And also give its working(dry run):)
    mani_jeddah's Avatar
    mani_jeddah Posts: 75, Reputation: -1
    Junior Member
     
    #2

    Oct 16, 2008, 09:59 AM

    although its your assignment but I will make it for you!

    #include<iostream>
    using namespace std;
    int fact(int,int);
    int main()
    {
    int ans ;
    int a ;
    cout << "Enter a number: "
    cin >> a ;
    ans = fact(a , 1);
    cout << ans ;
    return 0 ;
    }


    int fact(int b, int ans)
    {

    if(b == 0)
    return 1 ;
    else if(b == 1)
    return ans ;
    else
    ans *= b;
    return fact(b - 1, ans);
    }


    vote for my answer...

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Function Or Not? [ 1 Answers ]

Tell whether or not the pairing is a function Input Output 9 0 8 2 7 4 7 6 I think it is I'm just not sure it's the 2 sevens that Are really bothering me if someone can help id...

Quadratic function [ 1 Answers ]

I have another question! I really am lost? I don't get those.. Chris cuts half a rectangular lawn, 40m by 30m by moving strips of equal width around perimeter. Jerri cuts the small rectangle left How wode a strip does Chris cut so that they share equally? Help!

The function key [ 1 Answers ]

I have an IBM Thinkpad. When I press the "i" key the #5 appears. How can I stop this so when I press the "i" key the letter "i" will type?

TV Out Function On [ 0 Answers ]

I've got a DVD drive and the PowerDVD 5.0 player and every time I try to watch a newer DVD, I get the error message "TV out function error", I look at the details and it says I can't play copyright protected DVD's with the TVout function enabled. The weird thing is, ALL my graphics adapters just...


View more questions Search