loops - Create a program with php that will find the missing number in the series of numbers -


i need question, need write code in php

  • find missing number in sequence, regardless of numbers position in sequence.
  • the numbers increase same amount each time.
  • the output must number missing initial list, not list number in (i have worked out myself).

example number sequence, $sequence = 3, 5, 9, 11, 13 number 7 missing, don't know how code, im assuming use loops, wouldn't know start, must in php

a more simple way missing number(s) sequence, way see it:

<?php     $sequence = array(3, 5, 9, 11, 13);     $numbers = array(7, 9, 15);     $single_nr = 7;     function getmissingnumber(array $sequence, $single_nr = null, $numbers = array())     {         // check if exists in sequence array         // check single number         if($single_nr)         {             if(!in_array($single_nr, $sequence))             {                 echo $single_nr . " not in array" . "<br />";             }         }          // check array of numbers         if($numbers)         {             foreach($numbers $nr)             {                 if(!in_array($nr, $sequence))                 {                     echo $nr . " not in array" . "<br />";                 }             }         }     }      echo getmissingnumber($sequence, null, $numbers); ?> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -