Question: Program in C pls /* * Description: In the following program, there is a recursive function f1() and * another function f2() with a while

Program in C pls

/*

* Description: In the following program, there is a recursive function f1() and

* another function f2() with a while loop. Plese rewrite both functions such

* that f1() does use resursion and f2() becomes a recursive function.

*

* Notice: You can only rewrite the implementation of f1() and f2(). Please do not

* modify any other part of the code.

*/

#include

int f1 (void)

{ int tmp;

printf("Enter a positive integer: ");

scanf("%d", &tmp);

if (tmp > 0)

return tmp;

else

f1();

}

void f2 (int n)

{

while (n>1)

{ printf("%d -> ", n);

if (n%2 == 0)

n = n/2;

else

n++;

}

printf("%d ", n);

return;

}

int main (void)

{ int n;

n = f1();

f2(n);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!