Bird
0
0
DSA Cprogramming~5 mins

Check if Number is Prime in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a prime number?
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Click to reveal answer
intermediate
Why do we only check divisors up to the square root of a number when testing for primality?
Because if a number n is divisible by a number greater than its square root, it must also be divisible by a number smaller than the square root. So checking up to the square root is enough.
Click to reveal answer
beginner
What is the simplest method to check if a number is prime?
Try dividing the number by all integers from 2 up to the square root of the number. If none divide evenly, the number is prime.
Click to reveal answer
beginner
What should you return if the number is less than 2 in a prime check function?
Return false because numbers less than 2 are not prime by definition.
Click to reveal answer
beginner
In C, which data type is best to use for the number when checking primality?
Use an integer type like int or long depending on the range of numbers you want to check.
Click to reveal answer
Which number is NOT a prime number?
A2
B3
C4
D5
What is the smallest prime number?
A0
B2
C1
D3
When checking if 29 is prime, up to which number should you check for divisors?
A6
B14
C29
D5
If a number is divisible by 1 and itself only, it is:
APrime
BComposite
CEven
DOdd
Which of these is an efficient way to check primality?
ACheck divisibility up to sqrt(n)
BCheck divisibility up to n/2
CCheck divisibility up to n-1
DCheck divisibility only by 2
Explain how to check if a number is prime using a simple algorithm.
Think about dividing the number by smaller numbers.
You got /4 concepts.
    Why is it enough to check divisors only up to the square root of the number when testing primality?
    Consider how multiplication pairs work.
    You got /3 concepts.