PHP program to find the difference between the largest integer and the smallest integer which are created by 8 numbers from 0 to 9. The number that can be rearranged shall start with 0 as in 00135668.

bookmark

<?php
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s', $s);
    $s = str_split($s);
    rsort($s);
    $a = (int) implode('', $s);
    sort($s);
    $b = (int) implode('', $s);
    echo "Difference between the largest integer and the smallest integer:\n";
    echo $a - $b;
    echo PHP_EOL;
}
?>


Output:
1
34568729

Difference between the largest integer and the smallest integer:
75308643