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

The following function duck( ) is a part of some class which is used to check if a given number is…

Computer Science20253 marksFill in
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.0]
What is the expression or statement at ?1?
(b)[1.0]
What is the expression or statement at ?2?
(c)[1.0]
What is the expression or statement at ?3?

Answer

Answer (a)

AI
$i \mathrel{/}= 10$ (i.e. $i = i / 10$) - to move to the next higher digit of $i$ on each iteration.

Answer (b)

AI
$0$ - to check whether the current last digit $c$ is zero.

Answer (c)

AI
$-1$ - the initial value of $f$; if no zero digit is found, the loop finishes with $f$ still $-1$, so the function returns false.
Implementation of algorithms to solve problems

From ISC 2025 Computer Science Paper 1, question 2(iv).