Computer Science, asked by aahelibalu13, 9 hours ago

please write a program to enter a number and check whether it is divisibe by 4 or not it is computer not maths pls help its a emergency​

Answers

Answered by Steph0303
3

Logic:

Modulo Operator is represented by % symbol. It is an operator which is used to find the reminder when a number is divided by another number.

E.g.

4 modulo 2 is written as 4 % 2. This gives us the reminder when 4 is divided by 2. Hence the answer returned would be 0.

Now if we want to check whether a number is divisible by 2, all we need is to check the final value we get after using the modulo operator.

If the answer is equal to 0, then the number is divisible. If the answer is anything else other than 0, then the number is not divisible.

Few more examples:

  • a = 8 % 3 ⇒ a = 2 (This means 8 is not divisible by 3.)
  • b = 10 % 5 ⇒ b = 0 (This means 10 is divisible by 5.)

Python Program to check whether a number is divisible by 4:

#Program to check divisibility by 4.

number = int(input("Enter the number to be checked: "))

if (number % 4 == 0):

   print("Number is divisible by 4.")

else:

   print("Number is not divisible by 4.")

(Refer to the images for output.)

Attachments:
Similar questions