![]() |
VOOZH | about |
A composite number is a positive integer that is not prime. In other words, it has a positive divisor other than one or itself. First few composite numbers are 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, .........
How to check if a given number is a composite number or not?
Examples:
Input : n = 21
Output: Yes
The number is a composite number!
Input : n = 11
Output : No
The idea is simple, we can use any of the below methods used for prime checking. We just need to change return statements. Return true is changed to return false and vice versa.
In below code optimized school method is discussed.
Output:
false
true
Time Complexity:- O(sqrt(n))
Space Complexity:-O(1)
Program on Composite Numbers