Answer the question
In order to leave comments, you need to log in
How to make an algorithm. which to each digit of a number (eg 151)?
How to make an algorithm. which will add 1 to each digit of a number (for example, 151) (the result should be 262). As an additional option - do not use any kind of conversion to strings..?
Answer the question
In order to leave comments, you need to log in
<?php
$number1 = 567;
$number2 = 5;
$number3 = 367835;
function f($num) {
return $num + floor(0.11111111111*(10**(floor(log10($num))+1)));
}
echo(f($number1)."\n".f($number2)."\n".f($number3));
/*
678
6
478946
*/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question