27.11.14

Excercise-18 : Recursive Function Progamming



Write a program using recursive function in C++ to find factorial of a given integer number.

7 comments:

  1. #include
    using namespace std;
    class recursive

    {
    public:

    int rec(int x)
    {
    if(x<=1)
    return 1;

    else
    return(x*rec(x-1));
    }
    };

    int main()
    {
    recursive rc;
    int a;
    cin>>a;
    cout<<"the factorial is: "<<rc.rec(a);
    }

    ReplyDelete
  2. Noted. Found correct. It is quite appreciable that you did it using recursive with class.

    ReplyDelete
  3. #include
    using namespace std;
    int fact(int n);
    int main()
    {
    int n,result=0;
    cin>>n;
    cout<<"the factorial is:"<<fact(n);
    }
    int fact(int inp)
    {
    if(inp<=1)
    return 1;
    else
    return(inp*fact(inp-1));
    }

    ReplyDelete
  4. Dear Sir, Please visit:
    http://itlearn24.blogspot.com/2014/11/recursive-function-progamming.html

    ReplyDelete
  5. #include
    using namespace std;
    int fact(int r);
    int main()
    {
    int r;
    cin>>r;
    cout<< "The factorial is:"<<fact(r);
    return 0;
    }
    int fact(int r)
    {
    if(r!=1)
    return r*fact(r-1);
    }



    ReplyDelete

Comment Here