Given two integer number x and y, find how many number from x to y (both inclusive) are divisible by 4.
Take to inputs x and y
Run a for loop from x to y
Check if each number can be divided by 4. You can use the modulo operator for this.
When a number is divisible, increment a counter.
Finally, print the count.
I do not understand how to answer this
>Solution :
In python:
# Step 1: Get user input
x = int(input("Enter the starting number: "))
y = int(input("Enter the ending number: "))
# Step 2: Initialize the counter
count = 0
# Step 3: Loop through the range
for num in range(x, y+1):
# Step 4: Check if the number is divisible by 4
if num % 4 == 0:
# Step 5: Increment the count
count += 1
# Step 6: Print the result
print("The number of integers divisible by 4 between", x, "and", y, "is:", count)