‹ Back to the paper
With reference to the code given below, answer the questions that follow along with dry run /…
With reference to the code given below, answer the questions that follow along with dry run / working.
boolean num(int x)
{ int a=1;
for (int c=x; c>0; c/=10)
a *= 10;
return (x*x%a)==x;
}(a)[2.0]
What will the function num() return when the value of $x=25$?
(b)[1.0]
What is the method num() performing?
Answer
Answer (a)
AIDry run for $x = 25$:
$x*x = 625$, $625 \% 100 = 25$, and $25 == 25$ is true.
The function returns true.
| c | a |
| 25 | 10 |
| 2 | 100 |
| 0 | loop ends |
Answer (b)
AIIt checks whether x is an Automorphic number, i.e. whether the square of the number ends with the number itself (a is 10 raised to the number of digits of x).
From ISC 2023 Computer Science Paper 1, question 2(iii).