Write a PHP program to sum of all numerical values (positive integers) embedded in a sentence
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?php
$sum = 0;
$s = rtrim(fgets(STDIN));
if (preg_match_all('/[0-9]+/', $s, $a)) {
foreach ($a[0] as $v) {
$sum += (int) $v;
}
}
echo "Sum of the numeric values: ".$sum . PHP_EOL;
?>
Sample Input:
5 apple and 10 orange are rotten in the basket
Sample Output:
Sum of the numeric values: 15
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال