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

Choose the correct option.

What is the method solve() performing?

Computer Science20221 markMCQ
  • (i)HCF of ‘a’ and ‘b’
  • (ii)Prime Factors of ‘a’ and ‘b’
  • (iii)LCM of ‘a’ and ‘b’
  • (iv)None of the above
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: (iii)

Answer: (iii) LCM of 'a' and 'b' The loop finds the smallest i divisible by both a and b.
Methods

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