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

Choose the correct option.

What is the method test() performing?

Computer Science20221 markMCQ
  • (i)Prime number/Composite number
  • (ii)Armstrong number
  • (iii)Palindrome number
  • (iv)Perfect number
Show the code
int test(int n)
{
    if(n == 1) return 0;
    for (int i = 2; i <= (int)(Math.sqrt(n)); i++)
        if(n % i == 0)
            return 0;
    return 1;
}

Answer

Answer

AI

Correct option: (i)

Answer: (i) Prime number/Composite number The method returns 1 for a prime and 0 for a composite number, testing divisors up to the square root.
Methods

From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 27(b).