Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Consider the following functions: int func1(int x) { int r, s; r = 2 * x; if

ID: 3532542 • Letter: 3

Question

3. Consider the following functions:

int func1(int x)

{

      int r, s;

      r = 2 * x;

      if (r > 10)
      {

            s = x / 2;

      }

      else
      {

            s = x / 3;
      }

      return s - 2;

}

int func2(int a, int b)

{

      int r, s;

      s = 0;

      for(r = a; r < b; r++)

      {

            s++;

      }

      return s;

}

What is the output from the following program fragments?

            int a, b;

      a. a = 10;
         cout << func1(a) << endl;

      b. a = 5; b = 12;

         cout << func2(a, b) << endl;
      c. a = 8;

         b = func1(a);

         cout << a << " " << b << " " << func2(a, b) << endl;

Explanation / Answer

/*******please rate with 5 stars******/

a. 4.

//explanation:

fun1(10)==> r= 2*10=20==> s=20/3 =6 return value = 6-2 = 4;

b. 7. //explanation : fun2(5,12)==> s=s+1 for 7 times(i.e, 12-5) so output=7.

c. 8 3 0 //explanation:

fun1(8)==> r=2*8=16==> s=16/3=5 so b=5-2=3.

now fun2(8,3) ==> s=s+1 for negative time (i.e, 3-8) which is not possible , so output = 0(i.e, initial value of s)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote