Suppose that beta is an int variable Consider the following
Solution
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int beta;
cin>>beta;
switch(beta%7)
{
case 0:
case 1: beta = beta * beta;
break;
case 2: beta++;
break;
case 3: beta = static_cast<int>(sqrt(beta * 1.0));
break;
case 4: beta = beta +4;
break;
case 6: beta = beta--;
break;
default: beta = -10;
}
cout<<\"beta =\"<<beta;
return 0;
}
a. beta = 11
11%7 = 4 so case 4 will execute where beta = beta +4 ,beta = 11+4 =15. So beta = 15.
b. beta = 12
12%7 = 5. But case 5 is not defined so default case will execute where beta = -10
c. beta = 0
0%7 = 0. so case 0 will execute. nothing happens and beta has same value ie beta =0;
d. beta = 16
16%7 = 2 . case 2 will execute and beta++ will execute. So beta = 17
