Challenge - 5 Problems
Prime Checker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Prime Check for 29
What is the output of the following C# code that checks if 29 is prime?
DSA C#
using System; class Program { static bool IsPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } static void Main() { Console.WriteLine(IsPrime(29)); } }
Attempts:
2 left
💡 Hint
29 is a prime number because it has no divisors other than 1 and itself.
✗ Incorrect
The code checks divisors from 2 up to sqrt(29). Since none divide 29 evenly, it returns true.
❓ Predict Output
intermediateOutput of Prime Check for 1
What is the output of this C# code when checking if 1 is prime?
DSA C#
using System; class Program { static bool IsPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } static void Main() { Console.WriteLine(IsPrime(1)); } }
Attempts:
2 left
💡 Hint
Numbers less than or equal to 1 are not prime.
✗ Incorrect
The code returns false immediately for n <= 1.
❓ Predict Output
advancedOutput of Prime Check for 1000003
What is the output of this C# code when checking if 1000003 is prime?
DSA C#
using System; class Program { static bool IsPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } static void Main() { Console.WriteLine(IsPrime(1000003)); } }
Attempts:
2 left
💡 Hint
1000003 is a known prime number.
✗ Incorrect
The code correctly checks divisors up to sqrt(1000003) without overflow and finds no divisor.
❓ Predict Output
advancedOutput of Prime Check for 0
What is the output of this C# code when checking if 0 is prime?
DSA C#
using System; class Program { static bool IsPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } static void Main() { Console.WriteLine(IsPrime(0)); } }
Attempts:
2 left
💡 Hint
0 is not a prime number.
✗ Incorrect
The code returns false immediately for n <= 1.
❓ Predict Output
expertOutput of Prime Check for Negative Number -7
What is the output of this C# code when checking if -7 is prime?
DSA C#
using System; class Program { static bool IsPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } static void Main() { Console.WriteLine(IsPrime(-7)); } }
Attempts:
2 left
💡 Hint
Negative numbers are not prime.
✗ Incorrect
The code returns false immediately for n <= 1, including negative numbers.
