Title: Check whether the given number is
either Prime or Composite
If any number contains
two factors -> prime number
eg: 2, 3, 5,7,11,13,17,……
more than two factors -> Composite numbers
eg: 4,6,8,9,10,12,14,15,…..
note: 1 is neither prime nor composite
Program:
n=int(input("Enter n value\n"))
c=0
for i in range(1,n+1):
if(n%i==0):
c=c+1
if(c==2):
print(n," is a prime
number")
elif(c>2):
print(n," is a composite
number")
else:
print(n," is neither
prime nor composite")
Output:
Enter n value
1
1 is
neither prime nor composite
>>>
Enter n value
5
5 is a
prime number
>>>
Enter n value
8
8 is a
composite number
Comments
Post a Comment