Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. $array = array(1, 0, 6, 9, 4, 5, 2, 3, 8, 7);$chet=0;$nechet=0;
  3. $chetArray=array();
  4. $nechetArray=array();
  5.  
  6. function firstMission($chet,$nechet,$array){
  7.  
  8. for($i=0;$i<count($array);$i++){
  9. if($array[$i]%2==0){
  10. $chet++;
  11. }else{
  12. $nechet++;
  13. }
  14. }
  15.  
  16. echo "Четных: $chet, Нечетных:$nechet <br>";
  17. }
  18.  
  19. function secondMission($array,$chetArray,$nechetArray){
  20. for($i=0;$i<count($array);$i++){
  21. if($array[$i]%2==0){
  22. $chetArray[]=$array[$i];
  23. }else{
  24. $nechetArray[]=$array[$i];
  25. }
  26. }
  27. echo "Четный массив <br> ";
  28. printMas($chetArray);
  29. echo "<br>Нечетный массив <br> ";
  30. printMas($nechetArray);
  31. }
  32.  
  33.  
  34. /*function printMas($chetArray,$nechetArray){
  35. echo "Четный массив <br> ";
  36. for($i=0;$i<count($chetArray);$i++){
  37. echo "$chetArray[$i] ";
  38. }
  39. echo "<br>Нечетный массив <br> ";
  40. for($i=0;$i<count($chetArray);$i++){
  41. echo "$nechetArray[$i] ";
  42. }
  43. }*/
  44.  
  45. function printMas($array){
  46. for($i=0;$i<count($array);$i++){
  47. echo "$array[$i] ";
  48. }
  49. }
  50. firstMission($chet,$nechet,$array);
  51. secondMission($array,$chetArray,$nechetArray);
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement