Dana Vrajitoru
C311 Programming Languages

C311 Class Exercise 2

Date: Wednesday, March 1, 2023.
Due Date:Wednesday, March 8, 2023.

Ex. 1 Convert to Iterative

Convert the following tail recursive function to iterative:

int sequence1(int n)
{
    if (n < 5)
        return n;
    else if (n % 2 == 0)
        return sequence1(n/2);
    else
        return sequence1((n-1)/2);
}
Ex. 2 Convert to Tail Recursive

Convert the following recursive function to tail recursive:

int sequence2(int n) 
{
    if (n < 4)
        return n/2;
    else
        return 3 * sequence2(n-1);
Canvas Submission

Upload to Canvas, Assignments, Class Exercise 2, a file containing the solution, or just the text of the solution as the submission entry. Add a comment mentioning all the people in the team. One submission per team is sufficient.