‹ Back to the paper
Question 2(iv)
3 marks
Computer ScienceISC 2025 Computer Science Paper 1Case basedImplementation of algorithms to solve problems
Fill in the blanks marked ?1?, ?2? ... so that the code works.
The following function duck( ) is a part of some class which is used to check if a given number is…
The following function duck( ) is a part of some class which is used to check if a given number is a duck number or not. There are some places in the code marked by ?1?, ?2?, ?3? which may be replaced by a statement / expression so that the function works properly.
A number is said to be Duck if the digit zero (0) is present in it.
boolean duck(int a)
{ int f=-1;
if(a==0)
return true;
for(int i=a; i!=0;?1?)
{ int c = i%10;
if(c==?2?)
{f=1; break; }
}
return (f==?3?)? false:true;
}(a)[1]
What is the expression or statement at ?1?
(b)[1]
What is the expression or statement at ?2?
(c)[1]
What is the expression or statement at ?3?
Answer
Answer (a)
Blanks: i = i / 10
?1? = $i = i / 10$ (or $i /= 10$): removes the last digit so that the loop moves to the next digit.
Answer (b)
Blanks: 0
?2? = $0$: the digit $c$ is compared with zero.
Answer (c)
Blanks: -1
?3? = $-1$: if $f$ is still $-1$, no zero digit was found, so false is returned.