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

Recursive Function

Discussion in 'C++' started by kostea89, Sep 4, 2010.

  1. kostea89

    kostea89 New Member

    Joined:
    Sep 4, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello again. Can someone help me i cant solve this problem:
    Write a C program to develop recursive functions to read the number of items from a string and to sum the result. sorry for my english.
     
  2. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    A simple example of recursion would be:
    Code:
     
    void recurse()
    {
      recurse(); //Function calls itself
    }
    
    int main()
    {
      recurse(); //Sets off the recursion
    }
    
    for a better thing, u can use
    Code:
    #include <iostream>
    
    using namespace std;
    
    void recurse ( int count ) // Each call gets its own count
    {
      cout<< count <<"\n";
      // It is not necessary to increment count sinceeach function's
      //  variables are separate (so each count will be initialized one greater)
      recurse ( count + 1 );
    }
    
    int main()
    {
      recurse ( 1 ); //First function call, so it starts at one        
    }
    
     

Share This Page