Missing even and odd elements from the given arrays | Function to find the missing numbers ; To store the minimum and the maximum odd and even elements from the arrays ; To store the sum of the array elements ; Get the minimum and the maximum even elements from the array ; Get the minimum and the maximum odd elements from the array ; To store the total terms in the series and the required sum of the array ; Total terms from 2 to minEven ; Sum of all even numbers from 2 to minEven ; Total terms from 2 to maxEven ; Sum of all even numbers from 2 to maxEven ; Required sum for the even array ; Missing even number ; Total terms from 1 to minOdd ; Sum of all odd numbers from 1 to minOdd ; Total terms from 1 to maxOdd ; Sum of all odd numbers from 1 to maxOdd ; Required sum for the odd array ; Missing odd number ; Driver code
< ? php function findMissingNums ( $ even , $ sizeEven , $ odd , $ sizeOdd ) { $ minEven = PHP_INT_MAX ; $ maxEven = PHP_INT_MIN ; $ minOdd = PHP_INT_MAX ; $ maxOdd = PHP_INT_MIN ; $ sumEvenArr = $ sumOddArr = 0 ; for ( $ i = 0 ; $ i < $ sizeEven ; $ i ++ ) { $ minEven = min ( $ minEven , $ even [ $ i ] ) ; $ maxEven = max ( $ maxEven , $ even [ $ i ] ) ; $ sumEvenArr += $ even [ $ i ] ; } for ( $ i = 0 ; $ i < $ sizeOdd ; $ i ++ ) { $ minOdd = min ( $ minOdd , $ odd [ $ i ] ) ; $ maxOdd = max ( $ maxOdd , $ odd [ $ i ] ) ; $ sumOddArr += $ odd [ $ i ] ; } $ totalTerms = $ reqSum = 0 ; $ totalTerms = ( int ) ( $ minEven / 2 ) ; $ evenSumMin = $ totalTerms * ( $ totalTerms + 1 ) ; $ totalTerms = ( int ) ( $ maxEven / 2 ) ; $ evenSumMax = $ totalTerms * ( $ totalTerms + 1 ) ; $ reqSum = ( $ evenSumMax - $ evenSumMin + $ minEven ) ; echo " Even = " ▁ . ▁ ( $ reqSum ▁ - ▁ $ sumEvenArr ) ▁ . ▁ " " $ totalTerms = ( int ) ( ( $ minOdd / 2 ) + 1 ) ; $ oddSumMin = $ totalTerms * $ totalTerms ; $ totalTerms = ( int ) ( ( $ maxOdd / 2 ) + 1 ) ; $ oddSumMax = $ totalTerms * $ totalTerms ; $ reqSum = ( $ oddSumMax - $ oddSumMin + $ minOdd ) ; echo " Odd = " } $ even = array ( 6 , 4 , 8 , 14 , 10 ) ; $ sizeEven = count ( $ even ) ; $ odd = array ( 7 , 5 , 3 , 11 , 13 ) ; $ sizeOdd = count ( $ odd ) ; findMissingNums ( $ even , $ sizeEven , $ odd , $ sizeOdd ) ; ? >