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

With reference to the code given below, answer the questions that follow along with dry run /…

Computer Science20233 marksShort answer
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)

AI
Dry run for $x = 25$:
ca
2510
2100
0loop ends
$x*x = 625$, $625 \% 100 = 25$, and $25 == 25$ is true. The function returns true.

Answer (b)

AI
It 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).
Methods

From ISC 2023 Computer Science Paper 1, question 2(iii).