Last active
July 7, 2019 16:08
-
-
Save qutal/cd5f9821ef2ab1b991bb6e27eb0ad3aa to your computer and use it in GitHub Desktop.
RomecQuest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array(1, 0, 6, 9, 4, 5, 2, 3, 8, 7);$chet=0;$nechet=0; | |
$chetArray=array(); | |
$nechetArray=array(); | |
function firstMission($chet,$nechet,$array){ | |
for($i=0;$i<count($array);$i++){ | |
if($array[$i]%2==0){ | |
$chet++; | |
}else{ | |
$nechet++; | |
} | |
} | |
echo "Четных: $chet, Нечетных:$nechet <br>"; | |
} | |
function secondMission($array,$chetArray,$nechetArray){ | |
for($i=0;$i<count($array);$i++){ | |
if($array[$i]%2==0){ | |
$chetArray[]=$array[$i]; | |
}else{ | |
$nechetArray[]=$array[$i]; | |
} | |
} | |
echo "Четный массив <br> "; | |
printMas($chetArray); | |
echo "<br>Нечетный массив <br> "; | |
printMas($nechetArray); | |
} | |
/*function printMas($chetArray,$nechetArray){ | |
echo "Четный массив <br> "; | |
for($i=0;$i<count($chetArray);$i++){ | |
echo "$chetArray[$i] "; | |
} | |
echo "<br>Нечетный массив <br> "; | |
for($i=0;$i<count($chetArray);$i++){ | |
echo "$nechetArray[$i] "; | |
} | |
}*/ | |
function printMas($array){ | |
for($i=0;$i<count($array);$i++){ | |
echo "$array[$i] "; | |
} | |
} | |
firstMission($chet,$nechet,$array); | |
secondMission($array,$chetArray,$nechetArray); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//3 | |
$array = array(1, 0, 6, 9, 4, 5, 2, 3, 8, 7);//массив из 10 элементов | |
/* сортирует массив array методом пузырька по возрастанию*/ | |
for ($j = 0; $j < count($array) - 1; $j++){ | |
for ($i = 0; $i < count($array) - $j - 1; $i++){ | |
if ($array[$i] > $array[$i + 1]){//Если элемент массива больше, чем следующий, то они меняются местами | |
$tmp_var = $array[$i + 1]; | |
$array[$i + 1] = $array[$i]; | |
$array[$i] = $tmp_var; | |
} | |
} | |
} | |
var_dump($array);// выводит инфу об отсортированном массиве(отсортированный массив) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment