
Patrick B. answered 06/26/20
Math and computer tutor/teacher
Entering function g with x=1 and n=3
Statement Values
Entering function g x=1 ; n=3
Entering for loop x=1; n=3; i=0
inside for loop i mod 2 = 0 mod 2 = 0, so x = x*1 = x = 1
continue i=1;
if condition 1 mod 2 = 1, so condition fails
x-- x=x-1 = 1-1 = 0
if (x==0) 0==0 so the conidition it true;
breaks out of the for loop
returns 0
----------------------------------------------------------
using namespace std;
#include <iostream>
int g (int x, int n)
{
for (int i = 0; i < n; i++)
{
if (i % 2 == 0)
{
x *= i + 1;
continue;
}
x--;
if (x == 0)
{
break;
}
}
return x;
}
int main()
{
cout << g(1,3);
}