In C What is the output of the following int recint s int t

In C++,

What is the output of the following?

int rec(int s, int t){

        if (s*t == 0)

               return 0;

        return rec(s-2, t-3)+2;

}

void main(){

        cout << rec(8, 12) << endl;

}

Solution

Solution.cpp

#include <iostream>//header file for input output function

using namespace std;//it tells the compiler to link std namespace

int rec(int s, int t){//recursive function

        if (s*t == 0)

               return 0;
              
        return rec(s-2, t-3)+2;//for first call it returns 2,// second call it returns 4
                                ////for third call it returns 6 //for fourth call it returns 8
}

int main(){//main function

        cout << rec(8, 12) << endl;
        return 0;

}


output

8

In C++, What is the output of the following? int rec(int s, int t){ if (s*t == 0) return 0; return rec(s-2, t-3)+2; } void main(){ cout << rec(8, 12) <

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site