Учебные задачи PHP. Задача 12
Primary tabs
Решение для задачи из списка
<?php /** * Решение для задачи №12 из курса PHP * * Даны два массива по 20 элементов каждый (заполните случайными числами, * так чтобы среди элементов массива при очередном запуске программы могли * встретиться и отрицательные и положительные числа). * Сравните каждый 3-ий элемент 1-ого массива с каждый 2-ым элементов 2-ого массива - * сравнение проводите пока не закончится та выборка, которая короче. */ $countElem = 20; $arrayM = getRandomArray($countElem); $arrayN = getRandomArray($countElem); arrayCompare($arrayM, $arrayN); function arrayCompare($firstArray,$secondArray) { $firstCount = 2; $secondCount = 1; while ($firstCount < count($firstArray)) { if ($firstArray[$firstCount] < $secondArray[$secondCount]) { echo $firstCount." => ".$firstArray[$firstCount]." меньше ".$secondCount." => ".$secondArray[$secondCount]."<br>"; } elseif ($firstArray[$firstCount] > $secondArray[$secondCount]) { echo $firstCount." => ".$firstArray[$firstCount]." больше ".$secondCount." => ".$secondArray[$secondCount]."<br>"; } else { echo $firstCount." => ".$firstArray[$firstCount]." равно ".$secondCount." => ".$secondArray[$secondCount]."<br>"; } $firstCount += 3; $secondCount += 2; } } function getRandomArray($count) { $numbers = []; for ($i = 0; $i < $count; $i++) { $numbers[$i] = rand(1, 99) - 50; } return $numbers; } ?>
- Log in to post comments
- 1703 reads
vedro-compota
Mon, 09/16/2019 - 23:08
Permalink
решение засчитано
решение засчитано
_____________
матфак вгу и остальная классика =)