27 - Write a program in Python to input a number and determine whether the number is composite number or not.
Composite Numbers
Composite Numbers are numbers that have more than two factors. These numbers are also called composites. Composite numbers are just the opposite of prime numbers which have only two factors, i.e. 1 and the number itself. All the natural numbers which are not prime numbers are composite numbers as they can be divided by more than two numbers. For example, 6 is a composite number because it is divisible by 1, 2, 3 and 6.
Examples:
4, 6, 8, 9, 10 etc.
n=int(input("Enter the number: "))
for i in range(2,n+1):
if (n%i==0):
break
if(n==i):
print(n,"is not a composite number")
else:
print(n,"is a composite number")
Output:
Enter the number: 4
4 is a composite number
Enter the number: 5
5 is not a composite number
Enter the number: 9
9 is a composite number
No comments:
Post a Comment