Q BgQuestion:

Scholar
Karma Points: 203
Respect (80%):
posted by  Funkmasta on 5/22/2008 1:13:02 AM  |  status: Closed  

Recursive Equivalent of function

Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
int count(int x[], int n){
int i, ans;
    for (ans=i=0; i<n; i++)
       ans++;
       return ans;
}


Produce the recursive equivalent of this function.  Also, show the first call.

Bonus Point Alert! Earn +4 additional karma points for helping this annual member.

AAnswers:

Answer Question
Scholar
Karma Points: 332
posted by catherine chrysler on 5/22/2008 4:36:37 AM  |  status: Live
Asker's Rating: Helpful   
Funkmasta's comment:
"Thank you so muchfor the help. Your awesome"
Response Details:
The following code is recursive equivalent of the function in question.

#include <iostream>
using std::cout;
using std::cin;

int count(int ans, int n)
{
    if(ans < n)
    {
        return count(++ans, n);
    }
    else
        return ans;

}

int count2(int n){
int i, ans;
    for (ans=i=0; i<n; i++)
       ans++;
       return ans;
}


int main()
{
    cout << count(0, 5);    
}







Answer Question
Ask New Question

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different than tutoring »