Comparing Two Recursive code

PHOTO EMBED

Fri Jun 07 2024 21:53:11 GMT+0000 (Coordinated Universal Time)

Saved by @ayushg103 #c++

void f(int n)
{
    n--;
    if(n)
    f(n);
    cout<<"AYUSH"<<endl;
}

void f(int n)
{
    if(n)
    f(n-1);
    cout<<"AYUSH"<<endl;
}
content_copyCOPY

1) it will print n times We change value of n before recalling. 2) it will print n+1 times coz at 0 , it will print as it is out of if. first one print only one time coz it value of n at f(n) is n-1 we recalling using different value hence when n-2 is called then n==n-2