Composite Numbers in the range
You are given two integers M, N as input. Write a program to print all the composite numbers present in the given range (including M and N).
Input
The first line of input is an integer M. The second line of input is an integer N.
Explanation
In the given example, the composite numbers present in the range between
2 to 9 are 4, 6, 8, 9.So, the output should be
4
6
8
9
Sample Input 1
2
9
Sample Output 1
4
6
8
9
Sample Input 2
1
4
Sample Output 2
4
def compositeNumbers(M, N):
for item in range(M,N+1):
c = 0
for div in range(2,item//2+1):
if item%div == 0:
c +=1
if c >= 1:
print(item)
print("Sample Input 1")
print(2)
print(9)
print("Sample output 1")
compositeNumbers(2,9)
print("\n\n")
print("Sample Input 2")
print(1)
print(4)
print("Sample output 1")
compositeNumbers(1,4)
Comments
Leave a comment