‹ 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?
- (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
AICorrect option: (iv)
Answer: (iv) 24
The first i divisible by both 8 and 12 is 24, the LCM.
From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 30(a).