Skip to content
Advertisement

How to sum two rows input file numbers to one row output file (PHP) [closed]

Input data: In the input file INPUT.TXT there are two non-negative integers are given by two rows and the numbers are less than 10 powered by 100.

Output data: in the OUTPUT.TXT file is needed to return sum of the numbers to one row, without initial zeros

Example:

# input.txt output.txt
1 3 7
4

Advertisement

Answer

Check it , It will help you

$data = explode("n", file_get_contents('INPUT.TXT'));
$sum = intval($data[0])+intval($data[1]);
echo $sum;
file_put_contents('OUTPUT.TXT', $sum);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement