Q:

Write a PHP program to check if a given number is within 2 of a multiple of 10

0

Write a PHP program to check if a given number is within 2 of a multiple of 10.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($n)
{
   return $n % 10 <= 2 || $n % 10 >= 8;
 }

var_dump(test(3));
var_dump(test(7));
var_dump(test(8));
var_dump(test(21));

Sample Output:

bool(false)
bool(false)
bool(true)
bool(true)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now