PRASHNIKAप्रश्निका
‹ Back to the paper

Choose the correct option.

What will be the output of the method solve() when the value of a=8 and b=12?

Computer Science20222 marksMCQ
  • (i)4
  • (ii)96
  • (iii)0
  • (iv)24
Show the code
int solve(int a, int b)
{
    int i, l = 0;
    for(i = 1; i <= a * b; i++)
    {
        if(i % a == 0 && i % b == 0)
        {
            l = i;
            break;
        }
    }
    return l;
}

Answer

Answer

AI

Correct option: (iv)

Answer: (iv) 24 The first i divisible by both 8 and 12 is 24, the LCM.
Methods

From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 30(a).