-3

I have an php array of 99 numbers.

The array contains the digits 1 to 100 with one digit missing.

How to know the missing number?

Chinmay235
  • 3,236
  • 8
  • 62
  • 93

1 Answers1

2

Since you say you've found an answer yourself, here is a possible solution

$assignmentArray = array(1,2,3,4,5,6,7,8,10);

// find the missing fie... err.. missing value is actually more correct.
$missingNumber = array_sum(range(1, 10)) - array_sum($assignmentArray);
echo 'The missing number is: ' . $missingNumber;
JimL
  • 2,501
  • 1
  • 19
  • 19
  • This code is showing randomly single digit. I want to show sigle missing digit not randomly. – Chinmay235 Sep 13 '13 at 15:08
  • 1
    @ChinmaySahu: You should change the assignmentArray to reflect the array you are supposed to search trough. Since you have an array you obviously don't need to generate one. – JimL Sep 13 '13 at 15:09
  • When i am using **$assignmentArray=array(1,2,3,4,5,6,7,8,10);** then the missing number is showing **9** but it is not possible to huge number to assign in array. – Chinmay235 Sep 13 '13 at 15:11
  • Yes this is correct but problem is for huge number of array. Is it possible to define 1 to 100000 in a array? – Chinmay235 Sep 13 '13 at 15:23
  • @ChinmaySahu: yes just update my code to calculate however large of an input array you want. – JimL Sep 13 '13 at 15:26
  • Hello @JimL i am unable to post new question in stackoverflow due to (-) voting. Please give me my question +1 – Chinmay235 Sep 30 '13 at 05:23