An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program to display each digit, starting with the rightmost digit. Your program should also determine whether or not the number is divisible by 9. Test it on the following numbers:


n = 154368
n = 621594
n = 123456


Hint: Use the % operator to get each digit; then use / to remove that digit. So 154368 % 10 gives 8 and 154368 / 10 gives 15436. The next digit extracted should be 6, then 3 and so on

Respuesta :

The program is an illustration of the modulo operator

What is a modulo operator?

The modulo operator is an operator used to determine if a number is divisible by another

The main program

The program written in Python, where comments are used to explain each action is as follows:

#This defines the function

def divisible(n):

   #This sets a boolean value to false

   divcCheck = True

   #This initializes a counter to 0

   num=0

   #The following iterates and prints the digits of the number

   while n>0:

       a = n%10

       n = n - a

       n = n/10

       print(int(a),end=" ")

       #This checks if the digit is divisible by 9

       if (int(a)%9 != 0):

           divcCheck = False

   num = num + 1

   #This prints true or false, depending if the number is divisible by 9

   print(divcCheck)

Read more about python programs at:

https://brainly.com/question/16397886

ACCESS MORE