Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created August 18, 2015 20:27
Show Gist options
  • Save VictorFursa/652661a15a2bde4bdf28 to your computer and use it in GitHub Desktop.
Save VictorFursa/652661a15a2bde4bdf28 to your computer and use it in GitHub Desktop.
<?php
1) 1. Дано натуральное число* n. Заполнить одномерный массив "наоборот"
Пример №1:
Дано : $n = 10;
Получить: array(10,9,8,7,6,5,4,3,2,1);
$n = 10;
$array = array();
for($i = 1; $i <= $n;$i++ ) {
$array[] = $i;
}
$state = true;
while($state) {
$state = false;
for($i=0 ;$i < $n;$i++){
if(isset($array[$i+1])){
if($array[$i] < $array[$i+1]){
$state = true;
$buffer = $array[$i];
$array[$i] = $array[$i+1];
$array[$i+1] = $buffer;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment