Computer Science, asked by coffingaming660, 23 days ago

WAp that takes an integer and tests whether it is divisible by 2, 4 and 5. Apply divisibility rules that say:

a. a number is divisible by 2 if the number is ending in an even digit 0,2,4,6,8.

b. a number is divisible by 4 if last 2 digits of the number are divisible by 4.

c. a number is divisible by 5 if the number is ending in 0 or 5

Answers

Answered by Equestriadash
32

The following co‎des have been written using Python.

\tt n\ =\ int(in put("Enter\ a\ number:\ "))\\if\ str(n)[-1]\ in\ '02468':\\{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 2.")\\{\ \ \ \ \ }if\ int(str(n)[-2]\ +\ str(n)[-1])\%4\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 4\ as\ well.")\\{\ \ \ \ \ }if\ int(str(n)[-1])\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 5\ as\ well.")

\tt elif\ int(str(n)[-2]\ +\ str(n)[-1])\%4\ ==\ 0:\\{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 4.")\\{\ \ \ \ \ }if\ str(n)[-1]\ in\ '02468':\\{\ \ \ \ \ }{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 2\ as\ well.")\\{\ \ \ \ \ }if\ str(n)[-1]\ in\ '05':\\{\ \ \ \ \ }{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 5\ as\ well.")

\tt elif\ str(n)[-1]\ in\ '05':\\{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 5.")\\{\ \ \ \ \ }if\ int(str(n)[-2]\ +\ str(n)[-1])\%4\ ==\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 4\ as\ well.")\\{\ \ \ \ \ }if\ str(n)[-1]\ in\ '02468':\\{\ \ \ \ \ }{\ \ \ \ \ }print("The\ number\ is\ divisible\ by\ 2\ as\ well.")


Equestriadash: Thanks for the Brainliest! ^_^"
Similar questions