- Related Questions & Answers
- PHP program to find the first ‘n’ numbers that are missing in an array
- PHP program to find the sum of odd numbers within a given range
- PHP program to find missing elements from an array
- PHP program to find the sum of cubes of natural numbers that are odd
- PHP program to find the average of the first n natural numbers that are even
- How to find Kaprekar numbers within a given range using Python?
- PHP program to find standard deviation of values within an array
- Find missing element in a sorted array of consecutive numbers in C++
- Find missing element in a sorted array of consecutive numbers in Python
- PHP program to find if a number is present in a given sequence of numbers
- Find numbers a and b that satisfy the given condition in C++
- How to find the missing number in a given Array from number 1 to n in Java?
- Python - Find missing numbers in a sorted list range
- 8086 program to find the min value in a given array
- Python program to generate random numbers within a given range and store in a list?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To find the numbers within a given array that are missing, the code is as follows −

<?php function missing_nums($my_arr, $arr_len, $val) { sort($my_arr); sort($my_arr , $arr_len); $i = 0; while ($i < $n && $my_arr[$i] <= 0) $i++; $count = 0; $current_num = 1; while ($count < $k && $i < $arr_len) { if ($arr[$i] != $current_num) { echo $current_num , " "; $count++; } else $i++; $current_num++; } while ($count < $val) { echo $current_num , " "; $current_num++; $count++; } } $my_arr =array ( 6, 7, 9 ); $arr_len = sizeof($my_arr); $val = 5; print_r("The missing numbers in the array is "); missing_nums($my_arr, $arr_len, $val); ?>

The missing numbers in the array is 1 2 3 4 5

A function named ‘missing_nums’ is defined that checks to see if a number is missing from an array of continuous numbers. It iterates through the array and checks to see the count and the current_num that is being iterated over. If two values can’t be found when 1 is added to the previous number, it is considered to be missing.

Outside the function, the array is defined, its length is assigned to a variable and the number of missing numbers that need to be found is also defined. The function is called by passing these values as parameters and computed output is displayed on the console.

Advertisements