Write a PHP program to compute the sum of two given non-negative integers x and y as long as the sum has the same number of digits as x. If the sum has more digits than x then return x without y
<?php function test($x, $y) { return strlen((string)($x + $y)) > strlen((string)$x) ? $x : $x + $y; } echo (test(4, 5))."\n"; echo (test(7, 4))."\n"; echo (test(10, 10))."\n";
Sample Output:
9 7 20
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer