Divisible by 4 - MATLAB Cody - MATLAB Central

Problem 42406. Divisible by 4

Difficulty:Rate

Pursuant to the first problem in this series, this one involves checking for divisibility by 4.

Write a function to determine if a number is divisible by 4. This can be checked by a few slightly different methods:

  1. Check the last two digits for divisibility by four.
  2. From the wikipedia reference page: "If the tens digit is even, the ones digit must be 0, 4, or 8. If the tens digit is odd, the ones digit must be 2 or 6."
  3. Check the following sum for divisibility by four: twice the tens digit plus the ones digit.

Previous problem: divisible by 3. Next problem: divisible by 5.

Solution Stats

40.18% Correct | 59.82% Incorrect
Last Solution submitted on May 05, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers356

Suggested Problems

More from this Author139

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!