1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Recursion Question

Discussion in 'C' started by golf_girl32, Dec 11, 2010.

  1. golf_girl32

    golf_girl32 New Member

    Joined:
    Sep 28, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    How do I write a recursive function that counts the number of sequences that sum up to that number that the user inputs? I have most of the program but I'm not sure how to make the loop work.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int partition(int n, int max)
    {
      if(n==0)
        return(0);
      int ret = 0;
      if(n<=max)
        ret=1;
      for()
      {
    
      }
      return(ret);
    }
    
    int main()
    {
        cout << "Enter a number: "  << endl;
        cin >> n >> endl;
        return 0;
    }
    
     
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    can you write a mathematical formula for what you want to calculate?

    maybe this?

    sum=1+2+3+5+.....+n
     
    shabbir likes this.

Share This Page