"Program for Identity Matrix | PHP program to print Identity Matrix ; Checking if row is equal to column ; Driver Code"
How can the above be solved in PHP?

 < ? php function Identity ( $ num ) { $ row ; $ col ; for ( $ row = 0 ; $ row < $ num ; $ row ++ ) { for ( $ col = 0 ; $ col < $ num ; $ col ++ ) { if ( $ row == $ col ) echo 1 , " ▁ " ; else echo 0 , " ▁ " ; } echo "
 " ; } return 0 ; } $ size = 5 ; identity ( $ size ) ; ? >


"Program for Markov matrix | PHP code to check Markov Matrix ; outer loop to access rows and inner to access columns ; Find sum of current row ; Matrix to check ; calls the function check ( )"
How can the above be solved in PHP?

< ? php function checkMarkov ( $ m ) { $ n = 3 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum = 0 ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) $ sum = $ sum + $ m [ $ i ] [ $ j ] ; if ( $ sum != 1 ) return false ; } return true ; } $ m = array ( array ( 0 , 0 , 1 ) , array ( 0.5 , 0 , 0.5 ) , array ( 1 , 0 , 0 ) ) ; if ( checkMarkov ( $ m ) ) echo " ▁ yes ▁ " ; else echo " ▁ no ▁ " ; ? >


"Program for Mean Absolute Deviation | Function to find mean of the array elements . ; Calculate sum of all elements . ; Function to find mean absolute deviation of given elements . ; Calculate the sum of absolute deviation about mean . ; Return mean absolute deviation about mean . ; Driver Code"
How can the above be solved in PHP?

< ? php function Mean ( $ arr , $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum = $ sum + $ arr [ $ i ] ; return $ sum / $ n ; } function meanAbsoluteDeviation ( $ arr , $ n ) { $ absSum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ absSum = $ absSum + abs ( $ arr [ $ i ] - Mean ( $ arr , $ n ) ) ; return $ absSum / $ n ; } $ arr = array ( 10 , 15 , 15 , 17 , 18 , 21 ) ; $ n = sizeof ( $ arr ) ; echo meanAbsoluteDeviation ( $ arr , $ n ) ; ? >


"Program for Mean and median of an unsorted array | Function for calculating mean ; Function for calculating median ; First we sort the array ; check for even case ; Driver Code ; Function call"
How can the above be solved in PHP?

 < ? php function findMean ( & $ a , $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum += $ a [ $ i ] ; return ( double ) $ sum / ( double ) $ n ; } function findMedian ( & $ a , $ n ) { sort ( $ a ) ; if ( $ n % 2 != 0 ) return ( double ) $ a [ $ n / 2 ] ; return ( double ) ( $ a [ ( $ n - 1 ) / 2 ] + $ a [ $ n / 2 ] ) / 2.0 ; } $ a = array ( 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 ) ; $ n = sizeof ( $ a ) ; echo " Mean ▁ = ▁ " . findMean ( $ a , $ n ) . "
 " ; echo " Median ▁ = ▁ " . findMedian ( $ a , $ n ) ; ? >


"Program for Mobius Function | Returns value of mobius ( ) ; Handling 2 separately ; If 2 ^ 2 also divides N ; Check for all other prime factors ; If i divides n ; If i ^ 2 also divides N ; Driver code"
How can the above be solved in PHP?

 < ? php function mobius ( $ n ) { $ p = 0 ; if ( $ n % 2 == 0 ) { $ n = $ n / 2 ; $ p ++ ; if ( $ n % 2 == 0 ) return 0 ; } for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i = $ i + 2 ) { if ( $ n % $ i == 0 ) { $ n = $ n / $ i ; $ p ++ ; if ( $ n % $ i == 0 ) return 0 ; } } return ( $ p % 2 == 0 ) ? -1 : 1 ; } $ N = 17 ; echo " Mobius ▁ Functions ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " , $ N , " ▁ is : ▁ " , mobius ( $ N ) , "
 " ; echo " Mobius ▁ Functions ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " , 25 , " ▁ is : ▁ " , mobius ( 25 ) , "
 " ; echo " Mobius ▁ Functions ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " , 6 , " ▁ is : ▁ " , mobius ( 6 ) ; ? >


"Program for Muller Method | PHP Program to find root of a function , f ( x ) ; Function to calculate f ( x ) ; Taking f ( x ) = x ^ 3 + 2 x ^ 2 + 10 x - 20 ; Calculating various constants required to calculate x3 ; Taking the root which is closer to x2 ; checking for resemblance of x3 with x2 till two decimal places ; Driver main function"
How can the above be solved in PHP?


"Program for N | PHP Program to find nth term of Arithmetic progression ; using formula to find the Nth term t ( n ) = a ( 1 ) + ( n - 1 ) * d ; starting number ; Common difference ; N th term to be find ; Display the output"
How can the above be solved in PHP?

< ? php function Nth_of_AP ( $ a , $ d , $ N ) { return ( $ a + ( $ N - 1 ) * $ d ) ; } $ a = 2 ; $ d = 1 ; $ N = 5 ; echo ( " The ▁ " . $ N . " th ▁ term ▁ of ▁ the ▁ series ▁ is ▁ : ▁ " . Nth_of_AP ( $ a , $ d , $ N ) ) ; ? >


"Program for Newton Raphson Method | PHP program for implementation of Newton Raphson Method for solving equations ; An example function whose solution is determined using Bisection Method . The function is x ^ 3 - x ^ 2 + 2 ; Derivative of the above function which is 3 * x ^ x - 2 * x ; Function to find the root ; x ( i + 1 ) = x ( i ) - f ( x ) / f '(x) ; Initial values assumed"
How can the above be solved in PHP?

< ? php $ EPSILON = 0.001 ; function func ( $ x ) { return $ x * $ x * $ x - $ x * $ x + 2 ; } function derivFunc ( $ x ) { return 3 * $ x * $ x - 2 * $ x ; } function newtonRaphson ( $ x ) { global $ EPSILON ; $ h = func ( $ x ) / derivFunc ( $ x ) ; while ( abs ( $ h ) >= $ EPSILON ) { $ h = func ( $ x ) / derivFunc ( $ x ) ; $ x = $ x - $ h ; } echo " The ▁ value ▁ of ▁ the ▁ " . " root ▁ is ▁ : ▁ " , $ x ; } $ x0 = -20 ; newtonRaphson ( $ x0 ) ; ? >


"Program for Next Fit algorithm in Memory Management | Function to allocate memory to blocks as per Next fit algorithm ; Stores block id of the block allocated to a process ; pick each process and find suitable blocks according to its size ad assign to it ; Do not start from beginning ; allocate block j to p [ i ] process ; Reduce available memory in this block . ; mod m will help in traversing the blocks from starting block after we reach the end . ; Driver program"
How can the above be solved in PHP?

 < ? php function NextFit ( $ blockSize , $ m , $ processSize , $ n ) { $ allocation = array_fill ( 0 , $ n , -1 ) ; $ j = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { while ( $ j < $ m ) { if ( $ blockSize [ $ j ] >= $ processSize [ $ i ] ) { $ allocation [ $ i ] = $ j ; $ blockSize [ $ j ] -= $ processSize [ $ i ] ; break ; } $ j = ( $ j + 1 ) % $ m ; } } echo " Process No . Process Size Block no . " ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { echo " " . ( $ i ▁ + ▁ 1 ) . " " . $ processSize [ $ i ] . " " if ( $ allocation [ $ i ] != -1 ) echo ( $ allocation [ $ i ] + 1 ) ; else echo " Not ▁ Allocated " ; echo "
 " ; } } $ blockSize = array ( 5 , 10 , 20 ) ; $ processSize = array ( 10 , 20 , 5 ) ; $ m = count ( $ blockSize ) ; $ n = count ( $ processSize ) ; NextFit ( $ blockSize , $ m , $ processSize , $ n ) ; ? >


"Program for Perrin numbers | Optimized PHP program for n 'th perrin number ; Driver code"
How can the above be solved in PHP?


"Program for Rank of Matrix | PHP program to find rank of a matrix ; function for exchanging two rows of a matrix ; function for finding rank of matrix ; Before we visit current row ' row ' , we make sure that mat [ row ] [ 0 ] , ... . mat [ row ] [ row - 1 ] are 0. Diagonal element is not zero ; This makes all entries of current column as 0 except entry ' mat [ row ] [ row ] ' ; Diagonal element is already zero . Two cases arise : 1 ) If there is a row below it with non - zero entry , then swap this row with that row and process that row 2 ) If all elements in current column below mat [ r ] [ row ] are 0 , then remvoe this column by swapping it with last column and reducing number of columns by 1. ; Find the non - zero element in current column ; Swap the row with non - zero element with this row . ; If we did not find any row with non - zero element in current columnm , then all values in this column are 0. ; Reduce number of columns ; Copy the last column here ; Process this row again ; Uncomment these lines to see intermediate results display ( mat , R , C ) ; printf ( " \n " ) ; ; function for displaying the matrix ; Driver code"
How can the above be solved in PHP?

 < ? php $ R = 3 ; $ C = 3 ; function swap ( & $ mat , $ row1 , $ row2 , $ col ) { for ( $ i = 0 ; $ i < $ col ; $ i ++ ) { $ temp = $ mat [ $ row1 ] [ $ i ] ; $ mat [ $ row1 ] [ $ i ] = $ mat [ $ row2 ] [ $ i ] ; $ mat [ $ row2 ] [ $ i ] = $ temp ; } } function rankOfMatrix ( $ mat ) { global $ R , $ C ; $ rank = $ C ; for ( $ row = 0 ; $ row < $ rank ; $ row ++ ) { if ( $ mat [ $ row ] [ $ row ] ) { for ( $ col = 0 ; $ col < $ R ; $ col ++ ) { if ( $ col != $ row ) { $ mult = $ mat [ $ col ] [ $ row ] / $ mat [ $ row ] [ $ row ] ; for ( $ i = 0 ; $ i < $ rank ; $ i ++ ) $ mat [ $ col ] [ $ i ] -= $ mult * $ mat [ $ row ] [ $ i ] ; } } } else { $ reduce = true ; for ( $ i = $ row + 1 ; $ i < $ R ; $ i ++ ) { if ( $ mat [ $ i ] [ $ row ] ) { swap ( $ mat , $ row , $ i , $ rank ) ; $ reduce = false ; break ; } } if ( $ reduce ) { $ rank -- ; for ( $ i = 0 ; $ i < $ R ; $ i ++ ) $ mat [ $ i ] [ $ row ] = $ mat [ $ i ] [ $ rank ] ; } $ row -- ; } } return $ rank ; } function display ( $ mat , $ row , $ col ) { for ( $ i = 0 ; $ i < $ row ; $ i ++ ) { for ( $ j = 0 ; $ j < $ col ; $ j ++ ) print ( " ▁ $ mat [ $ i ] [ $ j ] " ) ; print ( "
 " ) ; } } $ mat = array ( array ( 10 , 20 , 10 ) , array ( -20 , -30 , 10 ) , array ( 30 , 50 , 0 ) ) ; print ( " Rank ▁ of ▁ the ▁ matrix ▁ is ▁ : ▁ " . rankOfMatrix ( $ mat ) ) ; ? >


"Program for Surface Area of Octahedron | utility Function ; Driver Code"
How can the above be solved in PHP?

< ? php function surface_area_octahedron ( $ side ) { return ( 2 * ( sqrt ( 3 ) ) * ( $ side * $ side ) ) ; } $ side = 7 ; echo ( " Surface ▁ area ▁ of ▁ octahedron ▁ = " ) ; echo ( surface_area_octahedron ( $ side ) ) ; ? >


"Program for Tower of Hanoi | Tower of Hanoi ( n - disk ) algorithm in PHP with Display of Pole / rod Contents the 3 poles representation ; Number of disks ; A , B and C are names of rods"
How can the above be solved in PHP?

 < ? php $ poles = array ( array ( ) , array ( ) , array ( ) ) ; function TOH ( $ n , $ A = " A " , $ B = " B " , $ C = " C " ) { if ( $ n > 0 ) { TOH ( $ n - 1 , $ A , $ C , $ B ) ; echo " Move ▁ disk ▁ from ▁ rod ▁ $ A ▁ to ▁ rod ▁ $ C ▁
 " ; move ( $ A , $ C ) ; dispPoles ( ) ; TOH ( $ n - 1 , $ B , $ A , $ C ) ; } else { return ; } } function initPoles ( $ n ) { global $ poles ; for ( $ i = $ n ; $ i >= 1 ; -- $ i ) { $ poles [ 0 ] [ ] = $ i ; } } function move ( $ source , $ destination ) { global $ poles ; if ( $ source == " A " ) $ ptr1 = 0 ; elseif ( $ source == " B " ) $ ptr1 = 1 ; else $ ptr1 = 2 ; if ( $ destination == " A " ) $ ptr2 = 0 ; elseif ( $ destination == " B " ) $ ptr2 = 1 ; else $ ptr2 = 2 ; $ top = array_pop ( $ poles [ $ ptr1 ] ) ; array_push ( $ poles [ $ ptr2 ] , $ top ) ; } function dispPoles ( ) { global $ poles ; echo " A : ▁ [ " . implode ( " , ▁ " , $ poles [ 0 ] ) . " ] ▁ " ; echo " B : ▁ [ " . implode ( " , ▁ " , $ poles [ 1 ] ) . " ] ▁ " ; echo " C : ▁ [ " . implode ( " , ▁ " , $ poles [ 2 ] ) . " ] ▁ " ; echo "

 " ; } $ numdisks = 4 ; initPoles ( $ numdisks ) ; echo " Tower ▁ of ▁ Hanoi ▁ Solution ▁ for ▁ $ numdisks ▁ disks : ▁

 " ; dispPoles ( ) ; TOH ( $ numdisks ) ; ? >


"Program for Volume and Surface Area of Cube | utility function ; driver function"
How can the above be solved in PHP?

 < ? php function areaCube ( $ a ) { return ( $ a * $ a * $ a ) ; } function surfaceCube ( $ a ) { return ( 6 * $ a * $ a ) ; } $ a = 5 ; echo ( " Area ▁ = ▁ " ) ; echo ( areaCube ( $ a ) ) ; echo ( "
 " ) ; echo ( " Total ▁ surface ▁ area ▁ = ▁ " ) ; echo ( surfaceCube ( $ a ) ) ; ? >


"Program for Volume and Surface Area of Cuboid | utility function ; Driver Code"
How can the above be solved in PHP?

 < ? php function areaCuboid ( $ l , $ h , $ w ) { return ( $ l * $ h * $ w ) ; } function surfaceAreaCuboid ( $ l , $ h , $ w ) { return ( 2 * $ l * $ w + 2 * $ w * $ h + 2 * $ l * $ h ) ; } $ l = 1 ; $ h = 5 ; $ w = 7 ; echo " Area ▁ = ▁ " , areaCuboid ( $ l , $ h , $ w ) , "
 " ; echo " Total ▁ Surface ▁ Area ▁ = ▁ " , surfaceAreaCuboid ( $ l , $ h , $ w ) ; ? >


"Program for Volume and Surface area of Frustum of Cone | Function to calculate Volume of frustum of cone ; Function to calculate Curved Surface area of frustum of cone ; Function to calculate Total Surface area of frustum of cone ; Driver Code ; Printing value of volume and surface area"
How can the above be solved in PHP?

 < ? php function volume ( $ r , $ R , $ h ) { $ pi = 3.14159 ; return ( 1 / ( 3 ) ) * $ pi * $ h * ( $ r * $ r + $ R * $ R + $ r * $ R ) ; } function curved_surface_area ( $ r , $ R , $ l ) { $ pi = 3.14159 ; return $ pi * $ l * ( $ R + $ r ) ; } function total_surface_area ( $ r , $ R , $ l , $ h ) { $ pi = 3.14159 ; return ( $ pi * $ l * ( $ R + $ r ) + $ pi * ( $ r * $ r + $ R * $ R ) ) ; } $ small_radius = 3 ; $ big_radius = 8 ; $ slant_height = 13 ; $ height = 12 ; echo ( " Volume ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; echo ( volume ( $ small_radius , $ big_radius , $ height ) ) ; echo ( "
 " ) ; echo ( " Curved ▁ Surface ▁ Area ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; echo ( curved_surface_area ( $ small_radius , $ big_radius , $ slant_height ) ) ; echo ( "
 " ) ; echo ( " Total ▁ Surface ▁ Area ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; echo ( total_surface_area ( $ small_radius , $ big_radius , $ slant_height , $ height ) ) ; ? >


"Program for centered nonagonal number | Function to find nth centered nonagonal number . ; Formula to find nth centered nonagonal number . ; Driver Code"
How can the above be solved in PHP?

< ? php function centeredNonagonal ( $ n ) { return ( 3 * $ n - 2 ) * ( 3 * $ n - 1 ) / 2 ; } $ n = 10 ; echo centeredNonagonal ( $ n ) ; ? >


"Program for cube sum of first n natural numbers | Returns sum of first n natural numbers ; Driver code"
How can the above be solved in PHP?

< ? php function sumOfSeries ( $ n ) { $ x ; if ( $ n % 2 == 0 ) $ x = ( $ n / 2 ) * ( $ n + 1 ) ; else $ x = ( ( $ n + 1 ) / 2 ) * $ n ; return $ x * $ x ; } $ n = 5 ; echo sumOfSeries ( $ n ) ; ? >


"Program for decimal to hexadecimal conversion | function to convert decimal to hexadecimal ; char array to store hexadecimal number ; counter for hexadecimal number array ; temporary variable to store remainder ; storing remainder in temp variable . ; check if temp < 10 ; printing hexadecimal number array in reverse order ; Driver Code"
How can the above be solved in PHP?

< ? php function decToHexa ( $ n ) { $ hexaDeciNum ; $ i = 0 ; while ( $ n != 0 ) { $ temp = 0 ; $ temp = $ n % 16 ; if ( $ temp < 10 ) { $ hexaDeciNum [ $ i ] = chr ( $ temp + 48 ) ; $ i ++ ; } else { $ hexaDeciNum [ $ i ] = chr ( $ temp + 55 ) ; $ i ++ ; } $ n = ( int ) ( $ n / 16 ) ; } for ( $ j = $ i - 1 ; $ j >= 0 ; $ j -- ) echo $ hexaDeciNum [ $ j ] ; } $ n = 2545 ; decToHexa ( $ n ) ; ? >


"Program for dot product and cross product of two vectors | PHP implementation for dot product and cross product of two vector . ; Function that return dot product of two vector array . ; Loop for calculate cot product ; Function to find cross product of two vector array . ; Driver Code ; dotproduct function call ; crossproduct function call ; Loop that print cross product of two vector array ."
How can the above be solved in PHP?

< ? php $ n = 3 ; function dotproduct ( $ vect_A , $ vect_B ) { global $ n ; $ product = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ product = $ product + $ vect_A [ $ i ] * $ vect_B [ $ i ] ; return $ product ; } function crossproduct ( $ vect_A , $ vect_B , $ cross_P ) { $ cross_P [ 0 ] = $ vect_A [ 1 ] * $ vect_B [ 2 ] - $ vect_A [ 2 ] * $ vect_B [ 1 ] ; $ cross_P [ 1 ] = $ vect_A [ 2 ] * $ vect_B [ 0 ] - $ vect_A [ 0 ] * $ vect_B [ 2 ] ; $ cross_P [ 2 ] = $ vect_A [ 0 ] * $ vect_B [ 1 ] - $ vect_A [ 1 ] * $ vect_B [ 0 ] ; return $ cross_P ; } $ vect_A = array ( 3 , -5 , 4 ) ; $ vect_B = array ( 2 , 6 , 5 ) ; $ cross_P = array_fill ( 0 , $ n , 0 ) ; echo " Dot ▁ product : " ; echo dotproduct ( $ vect_A , $ vect_B ) ; echo " Cross product : " $ cross_P = crossproduct ( $ vect_A , $ vect_B , $ cross_P ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ cross_P [ $ i ] . " ▁ " ; ? >


"Program for focal length of a lens | Function to determine the focal length of a lens ; variable to store the distance between the lens and the image ; variable to store the distance between the lens and the object"
How can the above be solved in PHP?

< ? php function focal_length ( $ image_distance , $ object_distance ) { return 1 / ( ( 1 / $ image_distance ) + ( 1 / $ object_distance ) ) ; } $ image_distance = 2 ; $ object_distance = 50 ; echo " Focal ▁ length ▁ of ▁ a ▁ lens ▁ is ▁ " , focal_length ( $ image_distance , $ object_distance ) , " ▁ units ▁ . " ; ? >


"Program for harmonic mean of numbers | Function that returns harmonic mean . ; Declare sum variables and initialize with zero ; Driver code"
How can the above be solved in PHP?

< ? php function harmonicMean ( $ arr , $ n ) { $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ sum = $ sum + ( float ) ( 1 / $ arr [ $ i ] ) ; return ( float ) ( $ n / $ sum ) ; } $ arr = array ( 13.5 , 14.5 , 14.8 , 15.2 , 16.1 ) ; $ n = sizeof ( $ arr ) ; echo ( harmonicMean ( $ arr , $ n ) ) ; ? >


"Program for harmonic mean of numbers | Function that returns harmonic mean . ; Driver code"
How can the above be solved in PHP?

< ? php function harmonicMean ( $ arr , $ freq , $ n ) { $ sum = 0 ; $ frequency_sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum = $ sum + ( float ) ( $ freq [ $ i ] / $ arr [ $ i ] ) ; $ frequency_sum = $ frequency_sum + $ freq [ $ i ] ; } return ( $ frequency_sum / $ sum ) ; } $ num = array ( 13 , 14 , 15 , 16 , 17 ) ; $ freq = array ( 2 , 5 , 13 , 7 , 3 ) ; $ n = sizeof ( $ num ) ; echo ( harmonicMean ( $ num , $ freq , $ n ) ) ; ? >


"Program for length of a string using recursion | Function to calculate length ; if we reach at the end of the string ; Driver Code"
How can the above be solved in PHP?

< ? php function recLen ( & $ str , $ i ) { if ( $ i == strlen ( $ str ) ) return 0 ; else return 1 + recLen ( $ str , $ i + 1 ) ; } $ str = " GeeksforGeeks " ; echo ( recLen ( $ str , 0 ) ) ; ? >


"Program for n | Function to find the Nth odd number ; Driver code"
How can the above be solved in PHP?

< ? php function nthOdd ( $ n ) { return ( 2 * $ n - 1 ) ; } $ n = 10 ; echo nthOdd ( $ n ) ; ? >


"Program for n | Function to find the nth even number ; Driver code"
How can the above be solved in PHP?

< ? php function nthEven ( $ n ) { return ( 2 * $ n ) ; } $ n = 10 ; echo nthEven ( $ n ) ; ? >


"Program for nth Catalan Number | A recursive function to find nth catalan number ; Base case ; catalan ( n ) is sum of catalan ( i ) * catalan ( n - i - 1 ) ; Driver Code"
How can the above be solved in PHP?

< ? php function catalan ( $ n ) { if ( $ n <= 1 ) return 1 ; $ res = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ res += catalan ( $ i ) * catalan ( $ n - $ i - 1 ) ; return $ res ; } for ( $ i = 0 ; $ i < 10 ; $ i ++ ) echo catalan ( $ i ) , " ▁ " ; ? >


"Program for nth Catalan Number | PHP program for nth Catalan Number A dynamic programming based function to find nth Catalan number ; Table to store results of subproblems ; Initialize first two values in table ; Fill entries in catalan [ ] using recursive formula ; Return last entry ; Driver Code"
How can the above be solved in PHP?

< ? php function catalanDP ( $ n ) { $ catalan = array ( ) ; $ catalan [ 0 ] = $ catalan [ 1 ] = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) { $ catalan [ $ i ] = 0 ; for ( $ j = 0 ; $ j < $ i ; $ j ++ ) $ catalan [ $ i ] += $ catalan [ $ j ] * $ catalan [ $ i - $ j - 1 ] ; } return $ catalan [ $ n ] ; } for ( $ i = 0 ; $ i < 10 ; $ i ++ ) echo catalanDP ( $ i ) , " ▁ " ;


"Program for nth Catalan Number | Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; A Binomial coefficient based function to find nth catalan number in O ( n ) time ; Calculate value of 2 nCn ; return 2 nCn / ( n + 1 ) ; Driver code"
How can the above be solved in PHP?

< ? php function binomialCoeff ( $ n , $ k ) { $ res = 1 ; if ( $ k > $ n - $ k ) $ k = $ n - $ k ; for ( $ i = 0 ; $ i < $ k ; ++ $ i ) { $ res *= ( $ n - $ i ) ; $ res = floor ( $ res / ( $ i + 1 ) ) ; } return $ res ; } function catalan ( $ n ) { $ c = binomialCoeff ( 2 * ( $ n ) , $ n ) ; return floor ( $ c / ( $ n + 1 ) ) ; } for ( $ i = 0 ; $ i < 10 ; $ i ++ ) echo catalan ( $ i ) , " ▁ " ; ? >


"Program for quotient and remainder of big number | Function to calculate the modulus ; Store the modulus of big number ; Do step by step division ; Update modulo by concatenating current digit . ; Update quotient ; Update mod for next iteration . ; Flag used to remove starting zeros ; Driver Code"
How can the above be solved in PHP?

 < ? php function modBigNumber ( $ num , $ m ) { $ vec ; $ x = 0 ; $ mod = 0 ; for ( $ i = 0 ; $ i < strlen ( $ num ) ; $ i ++ ) { $ digit = $ num [ $ i ] - '0' ; $ mod = $ mod * 10 + $ digit ; $ quo = ( int ) ( $ mod / $ m ) ; $ vec [ $ x ++ ] = $ quo ; $ mod = $ mod % $ m ; } echo " Remainder ▁ : ▁ " . $ mod . "
 " ; echo " Quotient ▁ : ▁ " ; $ zeroflag = 0 ; for ( $ i = 0 ; $ i < $ x ; $ i ++ ) { if ( $ vec [ $ i ] == 0 && $ zeroflag == 0 ) continue ; $ zeroflag = 1 ; echo $ vec [ $ i ] ; } return ; } $ num = "14598499948265358486" ; $ m = 487 ; modBigNumber ( $ num , $ m ) ; ? >


"Program for sum of arithmetic series | Efficient PHP code to find sum of arithmetic series . ; Driver code"
How can the above be solved in PHP?


"Program for sum of arithmetic series | Function to find sum of series . ; Driver Code"
How can the above be solved in PHP?


"Program for sum of cos ( x ) series | PHP program to find the sum of cos ( x ) series ; here x is in degree . we have to convert it to radian for using it with series formula , as in series expansion angle is in radian ; Driver Code"
How can the above be solved in PHP?

< ? php $ PI = 3.142 ; function cosXSertiesSum ( $ x , $ n ) { global $ PI ; $ x = $ x * ( $ PI / 180.0 ) ; $ res = 1 ; $ sign = 1 ; $ fact = 1 ; $ pow = 1 ; for ( $ i = 1 ; $ i < 5 ; $ i ++ ) { $ sign = $ sign * -1 ; $ fact = $ fact * ( 2 * $ i - 1 ) * ( 2 * $ i ) ; $ pow = $ pow * $ x * $ x ; $ res = $ res + $ sign * $ pow / $ fact ; } return $ res ; } $ x = 50 ; $ n = 5 ; echo cosXSertiesSum ( $ x , 5 ) ; ? >


"Program for weighted mean of natural numbers . | Function to calculate weighted mean . ; Take num array and corresponding weight array and initialize it . ; Calculate the size of array . ; Check the size of both array is equal or not ."
How can the above be solved in PHP?

< ? php function weightedMean ( $ X , $ W , $ n ) { $ sum = 0 ; $ numWeight = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ numWeight = $ numWeight + $ X [ $ i ] * $ W [ $ i ] ; $ sum = $ sum + $ W [ $ i ] ; } return ( float ) ( $ numWeight / $ sum ) ; } $ X = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ) ; $ W = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ) ; $ n = sizeof ( $ X ) ; $ m = sizeof ( $ W ) ; if ( $ n == $ m ) echo ( weightedMean ( $ X , $ W , $ n ) ) ; else echo ( " - 1" ) ; ? >


"Program for weighted mean of natural numbers . | Returns weighted mean assuming for numbers { 1 , 2 , . . n } and weights { 1 , 2 , . . n } ; Driver Code"
How can the above be solved in PHP?

< ? php function weightedMean ( $ n ) { return ( 2 * $ n + 1 ) / 3 ; } $ n = 10 ; echo ( weightedMean ( $ n ) ) ; ? >


"Program to Calculate the Perimeter of a Decagon | Function for finding the perimeter ; Driver Code"
How can the above be solved in PHP?

< ? php function CalPeri ( $ s ) { $ Perimeter = 10 * $ s ; echo " The ▁ Perimeter ▁ of ▁ Decagon ▁ is ▁ : ▁ $ Perimeter " ; } $ s = 5 ; CalPeri ( $ s ) ; ? >


"Program to Convert Hexadecimal Number to Binary | function to convert Hexadecimal to Binary Number ; Get the Hexadecimal number ; Convert HexaDecimal to Binary"
How can the above be solved in PHP?

< ? php function HexToBin ( $ hexdec ) { $ i = 0 ; while ( $ hexdec [ $ i ] ) { switch ( $ hexdec [ $ i ] ) { case '0' : echo "0000" ; break ; case '1' : echo "0001" ; break ; case '2' : echo "0010" ; break ; case '3' : echo "0011" ; break ; case '4' : echo "0100" ; break ; case '5' : echo "0101" ; break ; case '6' : echo "0110" ; break ; case '7' : echo "0111" ; break ; case '8' : echo "1000" ; break ; case '9' : echo "1001" ; break ; case ' A ' : case ' a ' : echo "1010" ; break ; case ' B ' : case ' b ' : echo "1011" ; break ; case ' C ' : case ' c ' : echo "1100" ; break ; case ' D ' : case ' d ' : echo "1101" ; break ; case ' E ' : case ' e ' : echo "1110" ; break ; case ' F ' : case ' f ' : echo "1111" ; break ; default : echo " Invalid hexadecimal digit " $ hexdec [ $ i ] ; } $ i ++ ; } } $ hexdec = "1AC5" ; echo " Equivalent Binary value is : " HexToBin ( $ hexdec ) ;


"Program to Convert Km / hr to miles / hr and vice versa | Function to convert kmph to mph ; Function to convert mph to kmph ; Driver Code"
How can the above be solved in PHP?

 < ? php function kmphTOmph ( $ kmph ) { return 0.6214 * $ kmph ; } function mphTOkmph ( $ mph ) { return $ mph * 1.60934 ; } $ kmph = 150 ; $ mph = 100 ; echo " speed ▁ in ▁ mph ▁ is ▁ " , kmphTOmph ( $ kmph ) , "
 " ; echo " speed ▁ in ▁ kmph ▁ is ▁ " , mphTOkmph ( $ mph ) ; ? >


"Program to add two fractions | Function to return gcd of a and b ; Function to convert the obtained fraction into it 's simplest form ; Finding gcd of both terms ; Converting both terms into simpler terms by dividing them by common factor ; Function to add two fractions ; Finding gcd of den1 and den2 ; Denominator of final fraction obtained finding LCM of den1 and den2 LCM * GCD = a * b ; Changing the fractions to have same denominator Numerator of the final fraction obtained ; Calling function to convert final fraction into it 's  simplest form ; Driver Code"
How can the above be solved in PHP?

 < ? php function gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return gcd ( $ b % $ a , $ a ) ; } function lowest ( & $ den3 , & $ num3 ) { $ common_factor = gcd ( $ num3 , $ den3 ) ; $ den3 = ( int ) $ den3 / $ common_factor ; $ num3 = ( int ) $ num3 / $ common_factor ; } function addFraction ( $ num1 , $ den1 , $ num2 , $ den2 , & $ num3 , & $ den3 ) { $ den3 = gcd ( $ den1 , $ den2 ) ; $ den3 = ( $ den1 * $ den2 ) / $ den3 ; $ num3 = ( $ num1 ) * ( $ den3 / $ den1 ) + ( $ num2 ) * ( $ den3 / $ den2 ) ; lowest ( $ den3 , $ num3 ) ; } $ num1 = 1 ; $ den1 = 500 ; $ num2 = 2 ; $ den2 = 1500 ; $ den3 ; $ num3 ; addFraction ( $ num1 , $ den1 , $ num2 , $ den2 , $ num3 , $ den3 ) ; echo $ num1 , " / " , $ den1 , " ▁ + ▁ " , $ num2 , " / " , $ den2 , " ▁ is ▁ equal ▁ to ▁ " , $ num3 , " / " , $ den3 , "
 " ; ? >


"Program to calculate Area Of Octagon | Utility function ; Driver Code"
How can the above be solved in PHP?

< ? php function areaOctagon ( $ side ) { return ( 2 * ( 1 + sqrt ( 2 ) ) * $ side * $ side ) ; } $ side = 4 ; echo ( " Area ▁ of ▁ Regular ▁ Octagon ▁ = ▁ " ) ; echo ( areaOctagon ( $ side ) ) ; ? >


"Program to calculate GST from original and net prices | PHP Program to compute GST from original and net prices . ; return value after calculate GST % ; Driver Code"
How can the above be solved in PHP?

< ? php function Calculate_GST ( $ org_cost , $ N_price ) { return ( ( ( $ N_price - $ org_cost ) * 100 ) / $ org_cost ) ; } $ org_cost = 100 ; $ N_price = 120 ; echo ( " GST ▁ = ▁ " ) ; echo ( Calculate_GST ( $ org_cost , $ N_price ) ) ; echo ( " ▁ % ▁ " ) ; ? >


"Program to calculate Profit Or Loss | Function to calculate Profit . ; Function to calculate Loss . ; Driver Code ."
How can the above be solved in PHP?

< ? php function Profit ( $ costPrice , $ sellingPrice ) { $ profit = ( $ sellingPrice - $ costPrice ) ; return $ profit ; } function Loss ( $ costPrice , $ sellingPrice ) { $ Loss = ( $ costPrice - $ sellingPrice ) ; return $ Loss ; } $ costPrice = 1500 ; $ sellingPrice = 2000 ; if ( $ sellingPrice == $ costPrice ) echo " No ▁ profit ▁ nor ▁ Loss " ; else if ( $ sellingPrice > $ costPrice ) echo Profit ( $ costPrice , $ sellingPrice ) . " ▁ Profit ▁ " ; else echo Loss ( $ costPrice , $ sellingPrice ) . " ▁ Loss ▁ " ; ? >


"Program to calculate Root Mean Square | Function that Calculate Root Mean Square ; Calculate square . ; Calculate Mean . ; Calculate Root . ; Driver code"
How can the above be solved in PHP?

< ? php function rmsValue ( $ arr , $ n ) { $ square = 0 ; $ mean = 0.0 ; $ root = 0.0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ square += pow ( $ arr [ $ i ] , 2 ) ; } $ mean = ( $ square / ( float ) ( $ n ) ) ; $ root = sqrt ( $ mean ) ; return $ root ; } $ arr = array ( 10 , 4 , 6 , 8 ) ; $ n = sizeof ( $ arr ) ; echo rmsValue ( $ arr , $ n ) ; ? >


"Program to calculate area and perimeter of a rhombus whose diagonals are given | calculate area and perimeter of a rhombus ; Driver code"
How can the above be solved in PHP?

 < ? php function rhombusAreaPeri ( $ d1 , $ d2 ) { $ area = ( $ d1 * $ d2 ) / 2 ; $ perimeter = 2 * sqrt ( pow ( $ d1 , 2 ) + pow ( $ d2 , 2 ) ) ; echo " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " . $ d1 . " ▁ and ▁ " . $ d2 . " ▁ is ▁ " . $ area . " . " . "
 " ; echo " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " . $ d1 . " ▁ and ▁ " . $ d2 . " ▁ is ▁ " . $ perimeter . " . " . "
 " ; } $ d1 = 2 ; $ d2 = 4 ; rhombusAreaPeri ( $ d1 , $ d2 ) ; ? >


"Program to calculate area and perimeter of equilateral triangle | Function to calculate Area of equilateral triangle ; Function to calculate Perimeter of equilateral triangle ; Driver Code"
How can the above be solved in PHP?

 < ? php function area_equi_triangle ( $ side ) { return sqrt ( 3 ) / 4 * $ side * $ side ; } function peri_equi_triangle ( $ side ) { return 3 * $ side ; } $ side = 4 ; echo ( " Area ▁ of ▁ Equilateral ▁ Triangle : ▁ " ) ; echo ( area_equi_triangle ( $ side ) ) ; echo ( "
 " ) ; echo ( " Perimeter ▁ of ▁ Equilateral ▁ Triangle : ▁ " ) ; echo ( peri_equi_triangle ( $ side ) ) ; ? >


"Program to calculate area and volume of a Tetrahedron | Function to calculate volume ; Driver Code"
How can the above be solved in PHP?

< ? php function vol_tetra ( $ side ) { $ volume = ( pow ( $ side , 3 ) / ( 6 * sqrt ( 2 ) ) ) ; return $ volume ; } $ side = 3 ; $ vol = vol_tetra ( $ side ) ; echo $ vol ; ? >


"Program to calculate area and volume of a Tetrahedron | Utility Function ; Driver Code"
How can the above be solved in PHP?

< ? php function area_of_tetrahedron ( $ side ) { return ( sqrt ( 3 ) * ( $ side * $ side ) ) ; } $ side = 3 ; echo " Area ▁ of ▁ Tetrahedron ▁ = ▁ " , area_of_tetrahedron ( $ side ) ; ? >


"Program to calculate distance between two points in 3 D | function to print distance ; Driver Code ; function call for distance"
How can the above be solved in PHP?


"Program to calculate distance between two points | Function to calculate distance ; Calculating distance ; Driver Code"
How can the above be solved in PHP?


"Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle | PHP program to find the area of inscribed circle of equilateral triangle ; function to find area of inscribed circle ; function to find perimeter of inscribed circle ; Driver code"
How can the above be solved in PHP?

< ? php $ PI = 3.14159265 ; function area_inscribed ( $ a ) { global $ PI ; return ( $ a * $ a * ( $ PI / 12 ) ) ; } function perm_inscribed ( $ a ) { global $ PI ; return ( $ PI * ( $ a / sqrt ( 3 ) ) ) ; } $ a = 6 ; echo ( " Area ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " ) ; echo ( area_inscribed ( $ a ) ) ; echo ( " Perimeter ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " ) ; echo ( perm_inscribed ( $ a ) ) ; ? >


"Program to calculate the area between two Concentric Circles | Function to find area between the two given concentric circles ; Declare value of pi ; Calculate area of outer circle ; Calculate area of inner circle ; Difference in areas ; Driver Code"
How can the above be solved in PHP?

< ? php function calculateArea ( $ x , $ y ) { $ pi = 3.1415926536 ; $ arx = $ pi * $ x * $ x ; $ ary = $ pi * $ y * $ y ; return ( $ arx - $ ary ) ; } $ x = 2 ; $ y = 1 ; echo calculateArea ( $ x , $ y ) ; ? >


"Program to calculate the number of odd days in given number of years | Function to return the count of odd days ; Count of years divisible by 100 and 400 ; Every 4 th year is a leap year ; Every 100 th year is divisible by 4 but is not a leap year ; Every 400 th year is divisible by 100 but is a leap year ; Total number of extra days ; modulo ( 7 ) for final answer ; Number of days"
How can the above be solved in PHP?

< ? php function oddDays ( $ N ) { $ hund1 = floor ( $ N / 100 ) ; $ hund4 = floor ( $ N / 400 ) ; $ leap = $ N >> 2 ; $ ord = $ N - $ leap ; if ( $ hund1 ) { $ ord += $ hund1 ; $ leap -= $ hund1 ; } if ( $ hund4 ) { $ ord -= $ hund4 ; $ leap += $ hund4 ; } $ days = $ ord + $ leap * 2 ; $ odd = $ days % 7 ; return $ odd ; } $ N = 100 ; echo oddDays ( $ N ) ; ? >


"Program to calculate the value of sin ( x ) and cos ( x ) using Expansion | Function for calculation ; Converting degrees to radian ; maps the sum along the series ; holds the actual value of sin ( n ) ; Driver Code"
How can the above be solved in PHP?

< ? php function cal_cos ( $ n ) { $ accuracy = 0.0001 ; $ n = $ n * ( 3.142 / 180.0 ) ; $ x1 = 1 ; $ cosx = $ x1 ; $ cosval = cos ( $ n ) ; $ i = 1 ; do { $ denominator = 2 * $ i * ( 2 * $ i - 1 ) ; $ x1 = - $ x1 * $ n * $ n / $ denominator ; $ cosx = $ cosx + $ x1 ; $ i = $ i + 1 ; } while ( $ accuracy <= abs ( $ cosval - $ cosx ) ) ; echo round ( $ cosx , 6 ) ; } $ n = 30 ; cal_cos ( $ n ) ; ? >


"Program to calculate value of nCr | PHP program To calculate the Value Of nCr ; Returns factorial of n ; Driver code"
How can the above be solved in PHP?

< ? php function nCr ( $ n , $ r ) { return fact ( $ n ) / ( fact ( $ r ) * fact ( $ n - $ r ) ) ; } function fact ( $ n ) { $ res = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ res = $ res * $ i ; return $ res ; } $ n = 5 ; $ r = 3 ; echo nCr ( $ n , $ r ) ; ? >


"Program to calculate volume of Ellipsoid | Function to find the volume ; Driver Code"
How can the above be solved in PHP?

< ? php function volumeOfEllipsoid ( $ r1 , $ r2 , $ r3 ) { $ pi = 3.14 ; return 1.33 * $ pi * $ r1 * $ r2 * $ r3 ; } $ r1 = 2.3 ; $ r2 = 3.4 ; $ r3 = 5.7 ; echo ( " volume ▁ of ▁ ellipsoid ▁ is ▁ : ▁ " ) ; echo ( volumeOfEllipsoid ( $ r1 , $ r2 , $ r3 ) ) ; ? >


"Program to calculate volume of Octahedron | utility Function ; Driver Function"
How can the above be solved in PHP?

< ? php function vol_of_octahedron ( $ side ) { return ( ( $ side * $ side * $ side ) * ( sqrt ( 2 ) / 3 ) ) ; } $ side = 3 ; echo ( " Volume ▁ of ▁ octahedron ▁ = " ) ; echo ( vol_of_octahedron ( $ side ) ) ; ? >


"Program to check Involutory Matrix | Program to implement involutory matrix . ; Function for matrix multiplication . ; Function to check involutory matrix . ; multiply function call . ; Driver Code ; Function call . If function return true then if part will execute otherwise else part will execute ."
How can the above be solved in PHP?

< ? php $ N = 3 ; function multiply ( $ mat , $ res ) { global $ N ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { for ( $ j = 0 ; $ j < $ N ; $ j ++ ) { $ res [ $ i ] [ $ j ] = 0 ; for ( $ k = 0 ; $ k < $ N ; $ k ++ ) $ res [ $ i ] [ $ j ] += $ mat [ $ i ] [ $ k ] * $ mat [ $ k ] [ $ j ] ; } } return $ res ; } function InvolutoryMatrix ( $ mat ) { global $ N ; $ res ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) $ res [ $ i ] [ $ j ] = 0 ; $ res = multiply ( $ mat , $ res ) ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { for ( $ j = 0 ; $ j < $ N ; $ j ++ ) { if ( $ i == $ j && $ res [ $ i ] [ $ j ] != 1 ) return false ; if ( $ i != $ j && $ res [ $ i ] [ $ j ] != 0 ) return false ; } } return true ; } $ mat = array ( array ( 1 , 0 , 0 ) , array ( 0 , -1 , 0 ) , array ( 0 , 0 , -1 ) ) ; if ( InvolutoryMatrix ( $ mat ) ) echo " Involutory ▁ Matrix " ; else echo " Not ▁ Involutory ▁ Matrix " ; ? >


"Program to check Plus Perfect Number | function to check plus perfect number ; calculating number of digits ; calculating plus perfect number ; checking whether number is plus perfect or not ; Driver Code"
How can the above be solved in PHP?

< ? php function checkplusperfect ( $ x ) { $ temp = $ x ; $ n = 0 ; while ( $ x != 0 ) { $ x /= 10 ; $ n ++ ; } $ x = $ temp ; $ sum = 0 ; while ( $ x != 0 ) { $ sum += pow ( $ x % 10 , $ n ) ; $ x /= 10 ; } return ( $ sum == $ temp ) ; } $ x = 9474 ; if ( checkplusperfect ( ! $ x ) ) echo " Yes " ; else echo " No " ; ? >


"Program to check diagonal matrix and scalar matrix | Program to check matrix is diagonal matrix or not . ; Function to check matrix is diagonal matrix or not . ; condition to check other elements except main diagonal are zero or not . ; Driver Code"
How can the above be solved in PHP?

 < ? php $ N = 4 ; function isDiagonalMatrix ( $ mat ) { global $ N ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) if ( ( $ i != $ j ) && ( $ mat [ $ i ] [ $ j ] != 0 ) ) return false ; return true ; } $ mat = array ( array ( 4 , 0 , 0 , 0 ) , array ( 0 , 7 , 0 , 0 ) , array ( 0 , 0 , 5 , 0 ) , array ( 0 , 0 , 0 , 1 ) ) ; if ( isDiagonalMatrix ( $ mat ) ) echo " Yes " , "
 " ; else echo " No " , "
 " ; ? >


"Program to check diagonal matrix and scalar matrix | Program to check matrix is scalar matrix or not . ; Function to check matrix is scalar matrix or not . ; Check all elements except main diagonal are zero or not . ; Check all diagonal elements are same or not . ; Driver Code ; Function call"
How can the above be solved in PHP?

< ? php $ N = 4 ; function isScalarMatrix ( $ mat ) { global $ N ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) for ( $ j = 0 ; $ j < $ N ; $ j ++ ) if ( ( $ i != $ j ) && ( $ mat [ $ i ] [ $ j ] != 0 ) ) return false ; for ( $ i = 0 ; $ i < $ N - 1 ; $ i ++ ) if ( $ mat [ $ i ] [ $ i ] != $ mat [ $ i + 1 ] [ $ i + 1 ] ) return false ; return true ; } $ mat = array ( array ( 2 , 0 , 0 , 0 ) , array ( 0 , 2 , 0 , 0 ) , array ( 0 , 0 , 2 , 0 ) , array ( 0 , 0 , 0 , 2 ) ) ; if ( isScalarMatrix ( $ mat ) ) echo " Yes " ; else echo " No " ; ? >


"Program to check if N is a Pentagonal Number | Function to determine if N is pentagonal or not . ; Substitute values of i in the formula . ; Driver Code"
How can the above be solved in PHP?

< ? php function isPentagonal ( int $ N ) { $ i = 1 ; $ M ; do { $ M = ( 3 * $ i * $ i - $ i ) / 2 ; $ i += 1 ; } while ( $ M < $ N ) ; return ( $ M == $ N ) ; } $ N = 12 ; if ( isPentagonal ( $ N ) ) echo $ N , " ▁ is ▁ pentagonal ▁ " ; else echo $ N , " ▁ is ▁ not ▁ pentagonal " ; ? >


"Program to check if a number is divisible by any of its digits | Function to check if given number is divisible by any of its digits ; check if any of digit divides n ; check if K divides N ; Driver Code"
How can the above be solved in PHP?

< ? php function isDivisible ( $ n ) { $ temp = $ n ; while ( $ n ) { $ k = $ n % 10 ; if ( $ temp % $ k == 0 ) return " YES " ; $ n = floor ( $ n / 10 ) ; } return " NO " ; } $ n = 9876543 ; echo isDivisible ( $ n ) ; ? >


"Program to check if a number is divisible by sum of its digits | Function to check if the given number is divisible by sum of its digits ; Find sum of digits ; check if sum of digits divides n ; Driver Code"
How can the above be solved in PHP?

< ? php function isDivisible ( $ n ) { $ temp = $ n ; $ sum = 0 ; while ( $ n ) { $ k = $ n % 10 ; $ sum += $ k ; $ n = ( int ) ( $ n / 10 ) ; } if ( $ temp % $ sum == 0 ) return " YES " ; return " NO " ; } $ n = 123 ; print ( isDivisible ( $ n ) ) ; ? >


"Program to check if tank will overflow , underflow or filled in given time | function to calculate the volume of tank ; function to print overflow / filled / underflow accordingly ; radius of the tank ; height of the tank ; rate of flow of water ; time given ; calculate the required time ; printing the result"
How can the above be solved in PHP?

< ? php function volume ( $ radius , $ height ) { return ( ( 22 / 7 ) * $ radius * $ radius * $ height ) ; } function check_and_print ( $ required_time , $ given_time ) { if ( $ required_time < $ given_time ) echo ( " Overflow " ) ; else if ( $ required_time > $ given_time ) echo ( " Underflow " ) ; else echo ( " Filled " ) ; } $ radius = 5 ; $ height = 10 ; $ rate_of_flow = 10 ; $ given_time = 70.0 ; $ required_time = volume ( $ radius , $ height ) / $ rate_of_flow ; check_and_print ( $ required_time , $ given_time ) ; ? >


"Program to check if the points are parallel to X axis or Y axis | To check for parallel line ; checking for parallel to X and Y axis condition ; To display the output ; Driver 's Code"
How can the above be solved in PHP?

< ? php function parallel ( $ n , $ a ) { $ x = true ; $ y = true ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) { if ( $ a [ $ i ] [ 0 ] != $ a [ $ i + 1 ] [ 0 ] ) $ x = false ; if ( $ a [ $ i ] [ 1 ] != $ a [ $ i + 1 ] [ 1 ] ) $ y = false ; } if ( $ x ) echo " parallel ▁ to ▁ Y ▁ Axis " ; else if ( y ) echo " parallel ▁ to ▁ X ▁ Axis " ; else echo " Not ▁ parallel ▁ to ▁ X " , " ▁ and ▁ Y ▁ Axis " ; } $ a = array ( array ( 1 , 2 ) , array ( 1 , 4 ) , array ( 1 , 6 ) , array ( 1 , 0 ) ) ; $ n = count ( $ a ) ; parallel ( $ n , $ a ) ; ? >


"Program to check if three points are collinear | function to check if point collinear or not ; Driver Code"
How can the above be solved in PHP?


"Program to check if water tank overflows when n solid balls are dipped in the water tank | function to find if tank will overflow or not ; cylinder capacity ; volume of water in tank ; volume of n balls ; total volume of water and n dipped balls ; condition to check if tank is in overflow state or not ; giving dimensions ; calling function"
How can the above be solved in PHP?

 < ? php function overflow ( $ H , $ r , $ h , $ N , $ R ) { $ tank_cap = 3.14 * $ r * $ r * $ H ; $ water_vol = 3.14 * $ r * $ r * $ h ; $ balls_vol = $ N * ( 4 / 3 ) * 3.14 * $ R * $ R * $ R ; $ vol = $ water_vol + $ balls_vol ; if ( $ vol > $ tank_cap ) { echo " Overflow " , "
 " ; } else { echo " Not ▁ in ▁ overflow ▁ state " , "
 " ; } } $ H = 10 ; $ r = 5 ; $ h = 5 ; $ N = 2 ; $ R = 2 ; overflow ( $ H , $ r , $ h , $ N , $ R ) ; ? >


"Program to check similarity of given two triangles | Function for AAA similarity ; Check for AAA ; Function for SAS similarity ; angle b / w two smallest sides is largest . ; since we take angle b / w the sides . ; Function for SSS similarity ; Check for SSS ; Driver Code ; function call for AAA similarity ; function call for SSS similarity ; function call for SAS similarity ; Check if triangles are similar or not"
How can the above be solved in PHP?


"Program to check whether 4 points in a 3 | Function to find equation of plane . ; checking if the 4 th point satisfies the above equation ; Driver Code ; function calling"
How can the above be solved in PHP?


"Program to check whether a number is Proth number or not | Utility function to check power of two ; Function to check if the Given number is Proth number or not ; check if k divides n or not ; Check if n / k is power of 2 or not ; update k to next odd number ; If we reach here means there exists no value of K Such that k is odd number and n / k is a power of 2 greater than k ; Get n ; Check n for Proth Number"
How can the above be solved in PHP?

< ? php function isPowerOfTwo ( $ n ) { return ( $ n && ! ( $ n & ( $ n - 1 ) ) ) ; } function isProthNumber ( $ n ) { $ k = 1 ; while ( $ k < ( $ n / $ k ) ) { if ( $ n % $ k == 0 ) { if ( isPowerOfTwo ( $ n / $ k ) ) return true ; } $ k = $ k + 2 ; } return false ; } $ n = 25 ; if ( isProthNumber ( $ n - 1 ) ) echo " YES " ; else echo " NO " ; ? >


"Program to compare m ^ n and n ^ m | function to compare m ^ n and n ^ m ; m ^ n ; n ^ m ; Driver Code ; function call to compare m ^ n and n ^ m"
How can the above be solved in PHP?

< ? php function check ( $ m , $ n ) { $ RHS = $ m * log ( $ n ) ; $ LHS = $ n * log ( $ m ) ; if ( $ LHS > $ RHS ) echo " m ^ n ▁ > ▁ n ^ m " ; else if ( $ LHS < $ RHS ) echo " m ^ n ▁ < ▁ n ^ m " ; else echo " m ^ n ▁ = ▁ n ^ m " ; } $ m = 987654321 ; $ n = 123456987 ; check ( $ m , $ n ) ; ? >


"Program to compare two fractions | Get max of the two fractions ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Compute ad - bc ; Driver Code"
How can the above be solved in PHP?

< ? php function maxFraction ( $ first , $ sec ) { $ a = $ first [ 0 ] ; $ b = $ first [ 1 ] ; $ c = $ sec [ 0 ] ; $ d = $ sec [ 1 ] ; $ Y = $ a * $ d - $ b * $ c ; return ( $ Y ) ? $ first : $ sec ; } $ first = array ( 3 , 2 ) ; $ sec = array ( 3 , 4 ) ; $ res = maxFraction ( $ first , $ sec ) ; echo $ res [ 0 ] . " / " . $ res [ 1 ] ; ? >


"Program to compute division upto n decimal places | PHP program to compute division upto n decimal places . ; Base cases ; Since n <= 0 , don 't   compute after the decimal ; Handling negative numbers ; Integral division ; Now one by print digits after dot using school division method . ; Driver Code"
How can the above be solved in PHP?


"Program to convert KiloBytes to Bytes and Bits | Function to calculates the bits ; calculates Bits 1 kilobytes ( s ) = 8192 bits ; Function to calculates the bytes ; calculates Bytes 1 KB = 1024 bytes ; Driver code"
How can the above be solved in PHP?

< ? php function Bits ( $ kilobytes ) { $ Bits = 0 ; $ Bits = $ kilobytes * 8192 ; return $ Bits ; } function Bytes ( $ kilobytes ) { $ Bytes = 0 ; $ Bytes = $ kilobytes * 1024 ; return $ Bytes ; } $ kilobytes = 1 ; echo $ kilobytes ; echo ( " ▁ Kilobytes ▁ = ▁ " ) ; echo Bytes ( $ kilobytes ) ; echo ( " ▁ Bytes ▁ and ▁ " ) ; echo Bits ( $ kilobytes ) ; echo ( " ▁ Bits . " ) ; ? >


"Program to convert a given number to words | A function that prints given number in words ; Get number of digits in given number ; Base cases ; The first string is not used , it is to make array indexing simple ; The first string is not used , it is to make array indexing simple ; The first two string are not used , they are to make array indexing simple ; Used for debugging purpose only ; For single digit number ; Iterate while num is not ' \0' ; Code path for first 2 digits ; here len can be 3 or 4 ; Code path for last 2 digits ; Need to explicitly handle 10 - 19. Sum of the two digits is used as index of " two _ digits " array of strings ; Need to explicitely handle 20 ; Rest of the two digit numbers i . e . , 21 to 99 ; Driver Code"
How can the above be solved in PHP?

 < ? php function convert_to_words ( $ num ) { $ len = strlen ( $ num ) ; if ( $ len == 0 ) { echo " empty ▁ string
 " ; return ; } if ( $ len > 4 ) { echo " Length ▁ more ▁ than ▁ 4 ▁ " . " is ▁ not ▁ supported
 " ; return ; } $ single_digits = array ( " zero " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " ) ; $ two_digits = array ( " " , " ten " , " eleven " , " twelve " , " thirteen " , " fourteen " , " fifteen " , " sixteen " , " seventeen " , " eighteen " , " nineteen " ) ; $ tens_multiple = array ( " " , " " , " twenty " , " thirty " , " forty " , " fifty " , " sixty " , " seventy " , " eighty " , " ninety " ) ; $ tens_power = array ( " hundred " , " thousand " ) ; echo $ num . " : ▁ " ; if ( $ len == 1 ) { echo $ single_digits [ $ num [ 0 ] - '0' ] . " ▁
 " ; return ; } $ x = 0 ; while ( $ x < strlen ( $ num ) ) { if ( $ len >= 3 ) { if ( $ num [ $ x ] - '0' != 0 ) { echo $ single_digits [ $ num [ $ x ] - '0' ] . " " ; echo $ tens_power [ $ len - 3 ] . " " ; } -- $ len ; } else { if ( $ num [ $ x ] - '0' == 1 ) { $ sum = $ num [ $ x ] - '0' + $ num [ $ x ] - '0' ; echo $ two_digits [ $ sum ] . " ▁
 " ; return ; } else if ( $ num [ $ x ] - '0' == 2 && $ num [ $ x + 1 ] - '0' == 0 ) { echo " twenty
 " ; return ; } else { $ i = $ num [ $ x ] - '0' ; if ( $ i > 0 ) echo $ tens_multiple [ $ i ] . " ▁ " ; else echo " " ; ++ $ x ; if ( $ num [ $ x ] - '0' != 0 ) echo $ single_digits [ $ num [ $ x ] - '0' ] . " ▁
 " ; } } ++ $ x ; } } convert_to_words ( "9923" ) ; convert_to_words ( "523" ) ; convert_to_words ( "89" ) ; convert_to_words ( "8" ) ; ? >


"Program to convert a given number to words | Set 2 | strings at index 0 is not used , it is to make array indexing simple ; strings at index 0 and 1 are not used , they is to make array indexing simple ; n is 1 - or 2 - digit number ; if n is more than 19 , divide it ; if n is non - zero ; Function to print a given number in words ; stores word representation of given number n ; handles digits at ten millions and hundred millions places ( if any ) ; handles digits at hundred thousands and one millions places ( if any ) ; handles digits at thousands and tens thousands places ( if any ) ; handles digit at hundreds places ( if any ) ; handles digits at ones and tens places ( if any ) ; long handles upto 9 digit no change to unsigned long long int to handle more digit number ; convert given number in words"
How can the above be solved in PHP?

 < ? php $ one = array ( " " , " one ▁ " , " two ▁ " , " three ▁ " , " four ▁ " , " five ▁ " , " six ▁ " , " seven ▁ " , " eight ▁ " , " nine ▁ " , " ten ▁ " , " eleven ▁ " , " twelve ▁ " , " thirteen ▁ " , " fourteen ▁ " , " fifteen ▁ " , " sixteen ▁ " , " seventeen ▁ " , " eighteen ▁ " , " nineteen ▁ " ) ; $ ten = array ( " " , " " , " twenty ▁ " , " thirty ▁ " , " forty ▁ " , " fifty ▁ " , " sixty ▁ " , " seventy ▁ " , " eighty ▁ " , " ninety ▁ " ) ; function numToWords ( $ n , $ s ) { global $ one , $ ten ; $ str = " " ; if ( $ n > 19 ) { $ str . = $ ten [ ( int ) ( $ n / 10 ) ] ; $ str . = $ one [ $ n % 10 ] ; } else $ str . = $ one [ $ n ] ; if ( $ n != 0 ) $ str . = $ s ; return $ str ; } function convertToWords ( $ n ) { $ out = " " ; $ out . = numToWords ( ( int ) ( $ n / 10000000 ) , " crore ▁ " ) ; $ out . = numToWords ( ( ( int ) ( $ n / 100000 ) % 100 ) , " lakh ▁ " ) ; $ out . = numToWords ( ( ( int ) ( $ n / 1000 ) % 100 ) , " thousand ▁ " ) ; $ out . = numToWords ( ( ( int ) ( $ n / 100 ) % 10 ) , " hundred ▁ " ) ; if ( $ n > 100 && $ n % 100 ) $ out . = " and ▁ " ; $ out . = numToWords ( ( $ n % 100 ) , " " ) ; return $ out ; } $ n = 438237764 ; echo convertToWords ( $ n ) . "
 " ; ? >


"Program to convert centimeter into meter and kilometer | Driver Code ; Converting centimeter into meter and kilometer"
How can the above be solved in PHP?

 < ? php $ cm ; $ meter ; $ kilometer ; $ cm = 1000 ; $ meter = $ cm / 100.0 ; $ kilometer = $ cm / 100000.0 ; echo " Length ▁ in ▁ meter ▁ = ▁ " , $ meter , " m " , "
 " ; echo " Length ▁ in ▁ Kilometer ▁ = ▁ " , $ kilometer , " km " , "
 " ; ? >


"Program to count digits in an integer ( 4 Different Methods ) | Recursive PHP program to count number of digits in a number ; Driver Code"
How can the above be solved in PHP?

< ? php function countDigit ( $ n ) { if ( $ n / 10 == 0 ) return 1 ; return 1 + countDigit ( ( int ) ( $ n / 10 ) ) ; } $ n = 345289467 ; print ( " Number ▁ of ▁ digits ▁ : ▁ " . ( countDigit ( $ n ) ) ) ; ? >


"Program to count vowels in a string ( Iterative and Recursive ) | Function to check the Vowel ; Returns count of vowels in str ; if ( isVowel ( $str [ $i ] ) ) Check for vowel ; string object ; Total numbers of Vowel"
How can the above be solved in PHP?

 < ? php function isVowel ( $ ch ) { $ ch = strtoupper ( $ ch ) ; return ( $ ch == ' A ' $ ch == ' E ' $ ch == ' I ' $ ch == ' O ' $ ch == ' U ' ) ; } function countVowels ( $ str ) { $ count = 0 ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) ++ $ count ; return $ count ; } $ str = " abc ▁ de " ; echo countVowels ( $ str ) . "
 " ; ? >


"Program to count vowels in a string ( Iterative and Recursive ) | Function to check the Vowel ; to count total number of vowel from 0 to n ; string object ; Total numbers of Vowel"
How can the above be solved in PHP?

< ? php function isVowel ( $ ch ) { $ ch = strtoupper ( $ ch ) ; return ( $ ch == ' A ' $ ch == ' E ' $ ch == ' I ' $ ch == ' O ' $ ch == ' U ' ) ; } function countVovels ( $ str , $ n ) { if ( $ n == 1 ) return isVowel ( $ str [ $ n - 1 ] ) ; return countVovels ( $ str , $ n - 1 ) + isVowel ( $ str [ $ n - 1 ] ) ; } $ str = " abc ▁ de " ; echo countVovels ( $ str , strlen ( $ str ) ) . " " ; ? >


"Program to determine focal length of a spherical mirror | Determines focal length of a spherical concave mirror ; Determines focal length of a spherical convex mirror ; Driver function"
How can the above be solved in PHP?

 < ? php function focal_length_concave ( $ R ) { return $ R / 2 ; } function focal_length_convex ( $ R ) { return - ( $ R / 2 ) ; } $ R = 30 ; echo " Focal ▁ length ▁ of ▁ spherical " , " concave ▁ mirror ▁ is ▁ : ▁ " , focal_length_concave ( $ R ) , " ▁ units
 " ; echo " Focal ▁ length ▁ of ▁ spherical " , " ▁ convex ▁ mirror ▁ is ▁ : ▁ " , focal_length_convex ( $ R ) , " ▁ units " ; ? >


"Program to determine the octant of the axial plane | Function to print octant ; Driver Code"
How can the above be solved in PHP?

 < ? php function octant ( $ x , $ y , $ z ) { if ( $ x >= 0 && $ y >= 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 1st ▁ octant
 " ; else if ( $ x < 0 && $ y >= 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 2nd ▁ octant
 " ; else if ( $ x < 0 && $ y < 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 3rd ▁ octant
 " ; else if ( $ x >= 0 && $ y < 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 4th ▁ octant
 " ; else if ( $ x >= 0 && $ y >= 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 5th ▁ octant
 " ; else if ( $ x < 0 && $ y >= 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 6th ▁ octant
 " ; else if ( $ x < 0 && $ y < 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 7th ▁ octant
 " ; else if ( $ x >= 0 && $ y < 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 8th ▁ octant
 " ; } $ x = 2 ; $ y = 3 ; $ z = 4 ; octant ( $ x , $ y , $ z ) ; $ x = -4 ; $ y = 2 ; $ z = -8 ; octant ( $ x , $ y , $ z ) ; $ x = -6 ; $ y = -2 ; $ z = 8 ; octant ( $ x , $ y , $ z ) ; ? >


"Program to determine the quadrant of the cartesian plane | Function to check quadrant ; Driver code ; Function call"
How can the above be solved in PHP?

< ? php function quadrant ( $ x , $ y ) { if ( $ x > 0 and $ y > 0 ) echo ( " lies ▁ in ▁ First ▁ quadrant " ) ; else if ( $ x < 0 and $ y > 0 ) echo ( " lies ▁ in ▁ Second ▁ quadrant " ) ; else if ( $ x < 0 and $ y < 0 ) echo ( " lies ▁ in ▁ Third ▁ quadrant " ) ; else if ( $ x > 0 and $ y < 0 ) echo ( " lies ▁ in ▁ Fourth ▁ quadrant " ) ; else if ( $ x == 0 and $ y > 0 ) echo ( " lies ▁ at ▁ positive ▁ y ▁ axis " ) ; else if ( $ x == 0 and $ y < 0 ) echo ( " lies ▁ at ▁ negative ▁ y ▁ axis " ) ; else if ( $ y == 0 and $ x < 0 ) echo ( " lies ▁ at ▁ negative ▁ x ▁ axis " ) ; else if ( $ y == 0 and $ x > 0 ) echo ( " lies ▁ at ▁ positive ▁ x ▁ axis " ) ; else echo ( " lies ▁ at ▁ origin " ) ; } $ x = 1 ; $ y = 1 ; quadrant ( $ x , $ y ) ; ? >


"Program to evaluate simple expressions | A utility function to check if a given character is operand ; utility function to find value of and operand ; This function evaluates simple expressions . It returns - 1 if the given expression is invalid . ; Base Case : Given expression is empty ; The first character must be an operand , find its value ; Traverse the remaining characters in pairs ; The next character must be an operator , and next to next an operand ; If next to next character is not an operand ; Update result according to the operator ; If not a valid operator ; Driver Code"
How can the above be solved in PHP?

 < ? php function isOperand ( $ c ) { return ( $ c >= '0' && $ c <= '9' ) ; } function value ( $ c ) { return ( $ c - '0' ) ; } function evaluate ( $ exp ) { $ len = strlen ( $ exp ) ; if ( $ len == 0 ) return -1 ; $ res = ( int ) ( value ( $ exp [ 0 ] ) ) ; for ( $ i = 1 ; $ i < $ len ; $ i += 2 ) { $ opr = $ exp [ $ i ] ; $ opd = $ exp [ $ i + 1 ] ; if ( ! isOperand ( $ opd ) ) return -1 ; if ( $ opr == ' + ' ) $ res += value ( $ opd ) ; else if ( $ opr == ' - ' ) $ res -= ( int ) ( value ( $ opd ) ) ; else if ( $ opr == ' * ' ) $ res *= ( int ) ( value ( $ opd ) ) ; else if ( $ opr == ' / ' ) $ res /= ( int ) ( value ( $ opd ) ) ; else return -1 ; } return $ res ; } $ expr1 = "1 + 2*5 + 3" ; $ res = evaluate ( $ expr1 ) ; ( $ res == -1 ) ? print ( $ expr1 . " ▁ is ▁ Invalid
 " ) : print ( " Value ▁ of ▁ " . $ expr1 . " ▁ is ▁ " . $ res . "
 " ) ; $ expr2 = "1 + 2*3" ; $ res = evaluate ( $ expr2 ) ; ( $ res == -1 ) ? print ( $ expr2 . " ▁ is ▁ Invalid
 " ) : print ( " Value ▁ of ▁ " . $ expr2 . " ▁ is ▁ " . $ res . "
 " ) ; $ expr3 = "4-2 + 6*3" ; $ res = evaluate ( $ expr3 ) ; ( $ res == -1 ) ? print ( $ expr3 . " ▁ is ▁ Invalid
 " ) : print ( " Value ▁ of ▁ " . $ expr3 . " ▁ is ▁ " . $ res . "
 " ) ; $ expr4 = "1 + + 2" ; $ res = evaluate ( $ expr4 ) ; ( $ res == -1 ) ? print ( $ expr4 . " ▁ is ▁ Invalid
 " ) : print ( " Value ▁ of ▁ " . $ expr4 . " ▁ is ▁ " . $ res . "
 " ) ; ? >


"Program to evaluate the expression ( ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¹ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’ Ã ¢ â ‚¬¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¦¡ X + 1 ) ^ 6 + ( ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¾¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¹ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â € š ¬ Ã …¡¬ ÃƒÆ ’ Ã ¢ â ‚¬¦¡¬ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬ Ãƒ ¢ Ã ¢ â € š ¬ Ã ¢ â € ž ¢ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒ ¢ Ã ¢ â ‚¬ Å ¾¢ ÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬¦¡ X | Function to find the sum ; Driver Code"
How can the above be solved in PHP?

< ? php function calculateSum ( $ n ) { $ a = ( int ) $ n ; return ( 2 * ( pow ( $ n , 6 ) + 15 * pow ( $ n , 4 ) + 15 * pow ( $ n , 2 ) + 1 ) ) ; } $ n = 1.4142 ; echo ceil ( calculateSum ( $ n ) ) ; ? >


"Program to find Circumference of a Circle | PHP program to find circumference of circle ; utility function ; Driver Code"
How can the above be solved in PHP?

< ? php $ PI = 3.1415 ; function circumference ( $ r ) { global $ PI ; $ cir = 2 * $ PI * $ r ; return $ cir ; } $ r = 5 ; echo " Circumference ▁ = ▁ " , circumference ( $ r ) ;


"Program to find GCD of floating point numbers | Recursive function to return gcd of a and b ; base case ; Driver Code"
How can the above be solved in PHP?

< ? php function gcd ( $ a , $ b ) { if ( $ a < $ b ) return gcd ( $ b , $ a ) ; if ( abs ( $ b ) < 0.001 ) return $ a ; else return ( gcd ( $ b , $ a - floor ( $ a / $ b ) * $ b ) ) ; } $ a = 1.20 ; $ b = 22.5 ; echo gcd ( $ a , $ b ) ; ? >


"Program to find GCD or HCF of two numbers | Recursive function to return gcd of a and b ; Driver code"
How can the above be solved in PHP?

< ? php function gcd ( $ a , $ b ) { if ( $ b == 0 ) return $ a ; return gcd ( $ b , $ a % $ b ) ; } $ a = 98 ; $ b = 56 ; echo " GCD ▁ of ▁ $ a ▁ and ▁ $ b ▁ is ▁ " , gcd ( $ a , $ b ) ; ? >


"Program to find GCD or HCF of two numbers | Recursive function to return gcd of a and b ; Everything divides 0 ; base case ; a is greater ; Driver code"
How can the above be solved in PHP?

< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; if ( $ b == 0 ) return $ a ; if ( $ a == $ b ) return $ a ; if ( $ a > $ b ) return gcd ( $ a - $ b , $ b ) ; return gcd ( $ a , $ b - $ a ) ; } $ a = 98 ; $ b = 56 ; echo " GCD ▁ of ▁ $ a ▁ and ▁ $ b ▁ is ▁ " , gcd ( $ a , $ b ) ; ? >


"Program to find HCF ( Highest Common Factor ) of 2 Numbers | Recursive function to return gcd of a and b ; Driver code"
How can the above be solved in PHP?


"Program to find HCF ( Highest Common Factor ) of 2 Numbers | Recursive function to return gcd of a and b ; Everything divides 0 ; base case ; a is greater ; Driver code"
How can the above be solved in PHP?

< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 && $ b == 0 ) return 0 ; if ( $ a == 0 ) return $ b ; if ( $ b == 0 ) return $ a ; if ( $ a == $ b ) return $ a ; if ( $ a > $ b ) return gcd ( $ a - $ b , $ b ) ; return gcd ( $ a , $ b - $ a ) ; } $ a = 98 ; $ b = 56 ; echo " GCD ▁ of ▁ $ a ▁ and ▁ $ b ▁ is ▁ " , gcd ( $ a , $ b ) ; ? >


"Program to find LCM of 2 numbers without using GCD | Function to return LCM of two numbers ; Driver Code"
How can the above be solved in PHP?

< ? php function findLCM ( $ a , $ b ) { $ lar = max ( $ a , $ b ) ; $ small = min ( $ a , $ b ) ; for ( $ i = $ lar ; ; $ i += $ lar ) { if ( $ i % $ small == 0 ) return $ i ; } } $ a = 5 ; $ b = 7 ; echo " LCM ▁ of ▁ " , $ a , " ▁ and ▁ " , $ b , " ▁ is ▁ " , findLCM ( $ a , $ b ) ; ? >


"Program to find LCM of two Fibonnaci Numbers | PHP Program to find LCM of Fib ( a ) and Fib ( b ) ; Create an array for memoization ; Function to return the n 'th Fibonacci number using table f[]. ; Base cases ; If fib ( n ) is already computed ; Applying recursive formula Note value n & 1 is 1 if n is odd , else 0. ; Function to return gcd of a and b ; Function to return the LCM of Fib ( a ) and Fib ( a ) ; Driver code"
How can the above be solved in PHP?

< ? php $ GLOBALS [ ' MAX ' ] = 1000 ; $ GLOBALS [ ' f ' ] = array ( ) ; for ( $ i = 0 ; $ i < $ GLOBALS [ ' MAX ' ] ; $ i ++ ) $ GLOBALS [ ' f ' ] [ $ i ] = 0 ; function fib ( $ n ) { if ( $ n == 0 ) return 0 ; if ( $ n == 1 $ n == 2 ) return ( $ GLOBALS [ ' f ' ] [ $ n ] = 1 ) ; if ( $ GLOBALS [ ' f ' ] [ $ n ] ) return $ GLOBALS [ ' f ' ] [ $ n ] ; $ k = ( $ n & 1 ) ? ( $ n + 1 ) / 2 : $ n / 2 ; $ GLOBALS [ ' f ' ] [ $ n ] = ( $ n & 1 ) ? ( fib ( $ k ) * fib ( $ k ) + fib ( $ k - 1 ) * fib ( $ k - 1 ) ) : ( 2 * fib ( $ k - 1 ) + fib ( $ k ) ) * fib ( $ k ) ; return $ GLOBALS [ ' f ' ] [ $ n ] ; } function gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return gcd ( $ b % $ a , $ a ) ; } function findLCMFibonacci ( $ a , $ b ) { return ( fib ( $ a ) * fib ( $ b ) ) / fib ( gcd ( $ a , $ b ) ) ; } $ a = 3 ; $ b = 12 ; echo findLCMFibonacci ( $ a , $ b ) ; ? >


"Program to find LCM of two numbers | Recursive function to return gcd of a and b ; Function to return LCM of two numbers ; Driver Code"
How can the above be solved in PHP?

< ? php function gcd ( $ a , $ b ) { if ( $ a == 0 ) return $ b ; return gcd ( $ b % $ a , $ a ) ; } function lcm ( $ a , $ b ) { return ( $ a / gcd ( $ a , $ b ) ) * $ b ; } $ a = 15 ; $ b = 20 ; echo " LCM ▁ of ▁ " , $ a , " ▁ and ▁ " , $ b , " ▁ is ▁ " , lcm ( $ a , $ b ) ; ? >


"Program to find Length of Bridge using Speed and Length of Train | function to calculate the length of bridge ; Assuming the input variables"
How can the above be solved in PHP?

< ? php function bridge_length ( $ trainLength , $ Speed , $ Time ) { return ( ( $ Time * $ Speed ) - $ trainLength ) ; } $ trainLength = 120 ; $ Speed = 30 ; $ Time = 18 ; echo " Length ▁ of ▁ bridge ▁ = ▁ " . bridge_length ( $ trainLength , $ Speed , $ Time ) . " ▁ meters " ; ? >


"Program to find Nth term of series 0 , 10 , 30 , 60 , 99 , 150 , 210 , 280. ... ... ... . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return 5 * pow ( $ n , 2 ) - 5 * $ n ; } $ N = 4 ; echo nthTerm ( $ N ) ; ? >


"Program to find Nth term of series 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203 , ... . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

 < ? php function nthTerm ( $ n ) { return 3 * pow ( $ n , 2 ) + 2 * $ n - 5 ; } $ N = 4 ; echo nthTerm ( $ N ) . "
 " ;


"Program to find Nth term of series 0 , 7 , 18 , 33 , 51 , 75 , 102 , 133 , ... . . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

 < ? php function nthTerm ( $ n ) { return 2 * pow ( $ n , 2 ) + $ n - 3 ; } $ N = 4 ; echo nthTerm ( $ N ) + "
 " ; ? >


"Program to find Nth term of series 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147 , ... . . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

 < ? php function nthTerm ( $ n ) { return 2 * pow ( $ n , 2 ) + 3 * $ n - 5 ; } $ N = 4 ; echo nthTerm ( $ N ) . "
 " ; ? >


"Program to find Nth term of series 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return 3 * pow ( $ n , 2 ) + $ n - 2 ; } $ N = 4 ; echo nthTerm ( $ N ) ; ? >


"Program to find Nth term of series 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

 < ? php function nthTerm ( $ n ) { return 4 * pow ( $ n , 2 ) - 3 * $ n + 2 ; } $ N = 4 ; echo nthTerm ( $ N ) . "
 " ; ? >


"Program to find Nth term of series 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

 < ? php function nthTerm ( $ n ) { return 2 * pow ( $ n , 2 ) + 4 * $ n - 2 ; } $ N = 4 ; echo nthTerm ( $ N ) . "
 " ; ? >


"Program to find Nth term of series 9 , 23 , 45 , 75 , 113. . . | calculate Nth term of series ; Get the value of N ; Find the Nth term and print it"
How can the above be solved in PHP?

< ? php function nthTerm ( $ N ) { return ( 2 * $ N + 3 ) * ( 2 * $ N + 3 ) - 2 * $ N ; } $ N = 4 ; echo nthTerm ( $ N ) ; ? >


"Program to find Nth term of the series 3 , 12 , 29 , 54 , 87 , ... | calculate Nth term of series ; Return Nth term ; declaration of number of terms ; Get the Nth term"
How can the above be solved in PHP?

< ? php function getNthTerm ( $ N ) { return 4 * pow ( $ N , 2 ) - 3 * $ N + 2 ; } $ N = 10 ; echo getNthTerm ( $ N ) ; ? >


"Program to find Perimeter / Circumference of Square and Rectangle | PHP program to find Circumference of a square ; Driver Code"
How can the above be solved in PHP?

< ? php function Circumference ( $ a ) { return 4 * $ a ; } $ a = 5 ; echo " Circumference ▁ of ▁ a ▁ " . " square ▁ is ▁ " , Circumference ( $ a ) ; ? >


"Program to find Star number | Returns n - th star number ; Driver code"
How can the above be solved in PHP?

< ? php function findStarNum ( $ n ) { return ( 6 * $ n * ( $ n - 1 ) + 1 ) ; } $ n = 3 ; echo findStarNum ( $ n ) ; ? >


"Program to find Sum of a Series a ^ 1 / 1 ! + a ^ 2 / 2 ! + a ^ 3 / 3 ! + a ^ 4 / 4 ! + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ . + a ^ n / n ! | Function to calculate sum of given series ; multiply ( a / i ) to previous term ; store result in res ; Driver Code"
How can the above be solved in PHP?

< ? php function sumOfSeries ( $ a , $ num ) { $ res = 0 ; $ prev = 1 ; for ( $ i = 1 ; $ i <= $ num ; $ i ++ ) { $ prev *= ( $ a / $ i ) ; $ res = $ res + $ prev ; } return ( $ res ) ; } $ n = 5 ; $ a = 2 ; echo ( sumOfSeries ( $ a , $ n ) ) ; ? >


"Program to find Sum of the series 1 * 3 + 3 * 5 + ... . | PHP program to find sum of first n terms ; Sn = n * ( 4 * n * n + 6 * n - 1 ) / 3 ; number of terms to be included in the sum ; find the Sn"
How can the above be solved in PHP?

< ? php function calculateSum ( $ n ) { return ( $ n * ( 4 * $ n * $ n + 6 * $ n - 1 ) / 3 ) ; } $ n = 4 ; echo " Sum = " ? >


"Program to find amount of water in a given glass | Returns the amount of water in jth glass of ith row ; A row number i has maximum i columns . So input column number must be less than i ; There will be i * ( i + 1 ) / 2 glasses till ith row ( including ith row ) and Initialize all glasses as empty ; Put all water in first glass ; Now let the water flow to the downward glasses till the row number is less than or / equal to i ( given row ) correction : X can be zero for side glasses as they have lower rate to fill ; Fill glasses in a given row . Number of columns in a row is equal to row number ; Get the water from current glass ; Keep the amount less than or equal to capacity in current glass ; Get the remaining amount ; Distribute the remaining amount to the down two glasses ; The index of jth glass in ith row will be i * ( i - 1 ) / 2 + j - 1 ; Driver Code ; Total amount of water"
How can the above be solved in PHP?

 < ? php function findWater ( $ i , $ j , $ X ) { if ( $ j > $ i ) { echo " Incorrect ▁ Input
 " ; return ; } $ glass = array_fill ( 0 , ( int ) ( $ i * ( $ i + 1 ) / 2 ) , 0 ) ; $ index = 0 ; $ glass [ $ index ] = $ X ; for ( $ row = 1 ; $ row < $ i ; ++ $ row ) { for ( $ col = 1 ; $ col <= $ row ; ++ $ col , ++ $ index ) { $ X = $ glass [ $ index ] ; $ glass [ $ index ] = ( $ X >= 1.0 ) ? 1.0 : $ X ; $ X = ( $ X >= 1.0 ) ? ( $ X - 1 ) : 0.0 ; $ glass [ $ index + $ row ] += ( double ) ( $ X / 2 ) ; $ glass [ $ index + $ row + 1 ] += ( double ) ( $ X / 2 ) ; } } return $ glass [ ( int ) ( $ i * ( $ i - 1 ) / 2 + $ j - 1 ) ] ; } $ i = 2 ; $ j = 2 ; $ X = 2.0 ; echo " Amount ▁ of ▁ water ▁ in ▁ jth ▁ " , " glass ▁ of ▁ ith ▁ row ▁ is : ▁ " . str_pad ( findWater ( $ i , $ j , $ X ) , 8 , '0' ) ; ? >


"Program to find correlation coefficient | function that returns correlation coefficient . ; sum of elements of array X . ; sum of elements of array Y . ; sum of X [ i ] * Y [ i ] . ; sum of square of array elements . ; use formula for calculating correlation coefficient . ; Driver Code ; Find the size of array . ; Function call to correlationCoefficient ."
How can the above be solved in PHP?

< ? php function correlationCoefficient ( $ X , $ Y , $ n ) { $ sum_X = 0 ; $ sum_Y = 0 ; $ sum_XY = 0 ; $ squareSum_X = 0 ; $ squareSum_Y = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sum_X = $ sum_X + $ X [ $ i ] ; $ sum_Y = $ sum_Y + $ Y [ $ i ] ; $ sum_XY = $ sum_XY + $ X [ $ i ] * $ Y [ $ i ] ; $ squareSum_X = $ squareSum_X + $ X [ $ i ] * $ X [ $ i ] ; $ squareSum_Y = $ squareSum_Y + $ Y [ $ i ] * $ Y [ $ i ] ; } $ corr = ( float ) ( $ n * $ sum_XY - $ sum_X * $ sum_Y ) / sqrt ( ( $ n * $ squareSum_X - $ sum_X * $ sum_X ) * ( $ n * $ squareSum_Y - $ sum_Y * $ sum_Y ) ) ; return $ corr ; } $ X = array ( 15 , 18 , 21 , 24 , 27 ) ; $ Y = array ( 25 , 25 , 27 , 31 , 32 ) ; $ n = sizeof ( $ X ) ; echo correlationCoefficient ( $ X , $ Y , $ n ) ; ? >


"Program to find count of numbers having odd number of divisors in given range | Function to count numbers having odd number of divisors in range [ A , B ] ; variable to odd divisor count ; iterate from a to b and count their number of divisors ; variable to divisor count ; if count of divisor is odd then increase res by 1 ; Driver code"
How can the above be solved in PHP?

< ? php function OddDivCount ( $ a , $ b ) { $ res = 0 ; for ( $ i = $ a ; $ i <= $ b ; ++ $ i ) { $ divCount = 0 ; for ( $ j = 1 ; $ j <= $ i ; ++ $ j ) { if ( $ i % $ j == 0 ) { ++ $ divCount ; } } if ( $ divCount % 2 ) { ++ $ res ; } } return $ res ; } $ a = 1 ; $ b = 10 ; echo OddDivCount ( $ a , $ b ) ; ? >


"Program to find equation of a plane passing through 3 points | Function to find equation of plane . ; Driver Code"
How can the above be solved in PHP?


"Program to find first N Iccanobif Numbers | Iterative function to reverse digits of num ; Function to print first N Icanobif Numbers ; Initialize first , second numbers ; Print first two numbers ; Reversing digit of previous two terms and adding them ; Driver Code"
How can the above be solved in PHP?

< ? php function reversDigits ( $ num ) { $ rev_num = 0 ; while ( $ num > 0 ) { $ rev_num = ( $ rev_num * 10 ) + ( $ num % 10 ) ; $ num = ( int ) ( $ num / 10 ) ; } return $ rev_num ; } function icanobifNumbers ( $ N ) { $ first = 0 ; $ second = 1 ; if ( $ N == 1 ) echo $ first ; else if ( $ N == 2 ) echo $ first , " ▁ " , $ second ; else { echo $ first , " " ▁ , ▁ $ second , ▁ " " for ( $ i = 3 ; $ i <= $ N ; $ i ++ ) { $ x = reversDigits ( $ first ) ; $ y = reversDigits ( $ second ) ; echo ( $ x + $ y ) , " ▁ " ; $ temp = $ second ; $ second = $ x + $ y ; $ first = $ temp ; } } } $ N = 12 ; icanobifNumbers ( $ N ) ; ? >


"Program to find greater value between a ^ n and b ^ n | Function to find the greater value ; If n is even ; Driver code"
How can the above be solved in PHP?

< ? php function findGreater ( $ a , $ b , $ n ) { if ( ! ( $ n & 1 ) ) { $ a = abs ( $ a ) ; $ b = abs ( $ b ) ; } if ( $ a == $ b ) echo " a ^ n ▁ is ▁ equal ▁ to ▁ b ^ n " ; else if ( $ a > $ b ) echo " a ^ n ▁ is ▁ greater ▁ than ▁ b ^ n " ; else echo " b ^ n ▁ is ▁ greater ▁ than ▁ a ^ n " ; } $ a = 12 ; $ b = 24 ; $ n = 5 ; findGreater ( $ a , $ b , $ n ) ; ? >


"Program to find largest element in an array | PHP function to find maximum in arr [ ] of size n ; Initialize maximum element ; Traverse array elements from second and compare every element with current max ; Driver Code"
How can the above be solved in PHP?

< ? php function largest ( $ arr , $ n ) { $ i ; $ max = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ arr [ $ i ] > $ max ) $ max = $ arr [ $ i ] ; return $ max ; } $ arr = array ( 10 , 324 , 45 , 90 , 9808 ) ; $ n = sizeof ( $ arr ) ; echo " Largest ▁ in ▁ given ▁ array ▁ is ▁ " , largest ( $ arr , $ n ) ; ? >


"Program to find largest element in an array | returns maximum in arr [ ] of size n ; Driver Code"
How can the above be solved in PHP?

< ? php function largest ( $ arr , $ n ) { return max ( $ arr ) ; } $ arr = array ( 10 , 324 , 45 , 90 , 9808 ) ; $ n = count ( $ arr ) ; echo largest ( $ arr , $ n ) ; ? >


"Program to find last two digits of 2 ^ n | Find the first digit ; Get the last digit from the number ; Remove last digit from number ; Get the last digit from the number ( last second of num ) ; Take last digit to ten 's position i.e.  last second digit ; Add the value of ones and tens to make it complete 2 digit number ; return the first digit ; Driver Code ; pow function used"
How can the above be solved in PHP?

< ? php function LastTwoDigit ( $ num ) { $ one = $ num % 10 ; $ num /= 10 ; $ tens = $ num % 10 ; $ tens *= 10 ; $ num = $ tens + $ one ; return $ num ; } $ n = 10 ; $ num = 1 ; $ num = pow ( 2 , $ n ) ; echo ( " Last ▁ " . 2 ) ; echo ( " ▁ digits ▁ of ▁ " . 2 ) ; echo ( " ^ " . $ n . " ▁ = ▁ " ) ; echo ( LastTwoDigit ( $ num ) ) ; ? >


"Program to find last two digits of 2 ^ n | Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; $x = $x % $p ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now $y = $y >> 1 ; y = y / 2 ; PHP function to calculate number of digits in x ; PHP function to print last 2 digits of 2 ^ n ; Generating 10 ^ 2 ; Calling modular exponentiation ; Printing leftmost zeros . Since ( 2 ^ n ) % 2 can have digits less then 2. In that case we need to print zeros ; If temp is not zero then print temp . If temp is zero then already printed ; Driver Code"
How can the above be solved in PHP?

< ? php function power ( $ x , $ y , $ p ) { while ( $ y > 0 ) { if ( $ y & 1 ) $ res = ( $ res * $ x ) % $ p ; $ x = ( $ x * $ x ) % $ p ; } return $ res ; } function numberOfDigits ( $ x ) { $ i = 0 ; while ( $ x ) { $ x /= 10 ; $ i ++ ; } return $ i ; } function LastTwoDigit ( $ n ) { echo ( " Last ▁ " . 2 ) ; echo ( " ▁ digits ▁ of ▁ " . 2 ) ; echo ( " ^ " . $ n . " ▁ = ▁ " ) ; $ temp = 1 ; for ( $ i = 1 ; $ i <= 2 ; $ i ++ ) $ temp *= 10 ; $ temp = power ( 2 , $ n , $ temp ) ; for ( $ i = 0 ; $ i < 2 - numberOfDigits ( $ temp ) ; $ i ++ ) echo ( 0 ) ; if ( $ temp ) echo ( $ temp ) ; } $ n = 72 ; LastTwoDigit ( $ n ) ; ? >


"Program to find minimum number of lectures to attend to maintain 75 % | Function to compute minimum lecture ; Formula to compute ; Driver Code"
How can the above be solved in PHP?

< ? php function minimumLectures ( $ m , $ n ) { $ ans = 0 ; if ( $ n < ceil ( 0.75 * $ m ) ) $ ans = ( int ) ceil ( ( ( 0.75 * $ m ) - $ n ) / 0.25 ) ; else $ ans = 0 ; return $ ans ; } $ M = 9 ; $ N = 1 ; echo minimumLectures ( $ M , $ N ) ; ? >


"Program to find nth term of the series 1 4 15 24 45 60 92 | function to calculate nth term of the series ; variable nth will store the nth term of series ; if n is even ; if n is odd ; return nth term ; Driver code"
How can the above be solved in PHP?


"Program to find number of solutions in Quadratic Equation | Method to check for solutions of equations ; If the expression is greater than 0 , then 2 solutions ; If the expression is equal 0 , then 2 solutions ; Else no solutions ; Driver Code"
How can the above be solved in PHP?

< ? php function checkSolution ( $ a , $ b , $ c ) { if ( ( ( $ b * $ b ) - ( 4 * $ a * $ c ) ) > 0 ) echo "2 ▁ solutions " ; else if ( ( ( $ b * $ b ) - ( 4 * $ a * $ c ) ) == 0 ) echo "1 ▁ solution " ; else echo " No ▁ solutions " ; } $ a = 2 ; $ b = 5 ; $ c = 2 ; checkSolution ( $ a , $ b , $ c ) ; ? >


"Program to find remainder when large number is divided by 11 | Function to return remainder ; len is variable to store the length of number string . ; loop that find remainder ; Driver code"
How can the above be solved in PHP?


"Program to find remainder when large number is divided by r | Function to Return Remainder ; len is variable to store the length of Number string . ; loop that find Remainder ; Return the remainder ; Get the large number as string ; Get the divisor R ; Find and print the remainder"
How can the above be solved in PHP?

< ? php function Remainder ( $ str , $ R ) { $ len = strlen ( $ str ) ; $ Num = 0 ; $ Rem = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ Num = $ Rem * 10 + ( $ str [ $ i ] - '0' ) ; $ Rem = $ Num % $ R ; } return $ Rem ; } $ str = "13589234356546756" ; $ R = 13 ; echo Remainder ( $ str , $ R ) ;


"Program to find remainder without using modulo or % operator | This function returns remainder of num / divisor without using % ( modulo ) operator ; Driver Code"
How can the above be solved in PHP?

< ? php function getRemainder ( $ num , $ divisor ) { $ t = ( $ num - $ divisor * ( int ) ( $ num / $ divisor ) ) ; return $ t ; } echo getRemainder ( 100 , 7 ) ; ? >


"Program to find simple interest | We can change values here for different inputs ; Calculate simple interest ; Print the resultant value of SI"
How can the above be solved in PHP?


"Program to find sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! | Function to find the factorial of a number ; Function to compute the sum ; Iterate the loop till n and compute the formula ; Get x and n ; Print output"
How can the above be solved in PHP?

< ? php function fact ( $ n ) { if ( $ n == 1 ) return 1 ; return $ n * fact ( $ n - 1 ) ; } function sum ( $ x , $ n ) { $ total = 1.0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ total = $ total + ( pow ( $ x , $ i ) / fact ( $ i + 1 ) ) ; } return $ total ; } $ x = 5 ; $ n = 4 ; echo " Sum ▁ is : ▁ " , sum ( $ x , $ n ) ; ? >


"Program to find sum of first n natural numbers | Returns sum of first n natural numbers ; Driver code"
How can the above be solved in PHP?

< ? php function findSum ( $ n ) { $ sum = 0 ; for ( $ x = 1 ; $ x <= $ n ; $ x ++ ) $ sum = $ sum + $ x ; return $ sum ; } $ n = 5 ; echo findSum ( $ n ) ; ? >


"Program to find sum of first n natural numbers | Returns sum of first n natural numbers ; If n is odd , ( n + 1 ) must be even ; Driver code"
How can the above be solved in PHP?

< ? php function findSum ( $ n ) { if ( $ n % 2 == 0 ) return ( $ n / 2 ) * ( $ n + 1 ) ; else return ( ( $ n + 1 ) / 2 ) * $ n ; } $ n = 5 ; echo findSum ( $ n ) ; ? >


"Program to find sum of harmonic series | Function to return sum of harmonic series ; Driver Code"
How can the above be solved in PHP?


"Program to find sum of harmonic series | PHP program to find sum of harmonic series using recursion ; Base condition ; Driver Code"
How can the above be solved in PHP?

 < ? php function sum ( $ n ) { if ( $ n < 2 ) return 1 ; else return 1 / $ n + ( sum ( $ n - 1 ) ) ; } echo sum ( 8 ) . "
 " ; echo sum ( 10 ) ; ? >


"Program to find sum of series 1 * 2 * 3 + 2 * 3 * 4 + 3 * 4 * 5 + . . . + n * ( n + 1 ) * ( n + 2 ) | Function to calculate sum of series . ; Driver Code"
How can the above be solved in PHP?

< ? php function sumOfSeries ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ sum = $ sum + $ i * ( $ i + 1 ) * ( $ i + 2 ) ; return $ sum ; } $ n = 10 ; echo sumOfSeries ( $ n ) ; ? >


"Program to find sum of series 1 + 1 / 2 + 1 / 3 + 1 / 4 + . . + 1 / n | Function to return sum of 1 / 1 + 1 / 2 + 1 / 3 + . . + 1 / n ; Driver Code"
How can the above be solved in PHP?


"Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | Function that find sum of series . ; Driver Code ; Function call"
How can the above be solved in PHP?

< ? php function sumOfSeries ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) for ( $ j = 1 ; $ j <= $ i ; $ j ++ ) $ sum = $ sum + $ i ; return $ sum ; } $ n = 10 ; echo ( sumOfSeries ( $ n ) ) ; ? >


"Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | Function to find sum of series . ; Driver Code ; Function call"
How can the above be solved in PHP?

< ? php function sumOfSeries ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ sum = $ sum + $ i * $ i ; return $ sum ; } $ n = 10 ; echo ( sumOfSeries ( $ n ) ) ; ? >


"Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | Function to find sum of series . ; Driver Code"
How can the above be solved in PHP?

< ? php function sumOfSeries ( $ n ) { return ( $ n * ( $ n + 1 ) * ( 2 * $ n + 1 ) ) / 6 ; } $ n = 10 ; echo ( sumOfSeries ( $ n ) ) ; ? >


"Program to find sum of the given sequence | function to find moudulo inverse under 10 ^ 9 + 7 ; Function to find the sum of the given sequence ; Driver code"
How can the above be solved in PHP?

< ? php function modInv ( $ x ) { $ MOD = 1000000007 ; $ n = $ MOD - 2 ; $ result = 1 ; while ( $ n ) { if ( $ n & 1 ) $ result = $ result * $ x % $ MOD ; $ x = $ x * $ x % $ MOD ; $ n = $ n / 2 ; } return $ result ; } function getSum ( $ n , $ k ) { $ MOD = 1000000007 ; $ ans = 1 ; for ( $ i = $ n + 1 ; $ i > $ n - $ k ; $ i -- ) $ ans = $ ans * $ i % $ MOD ; $ ans = $ ans * modInv ( $ k + 1 ) % $ MOD ; return $ ans ; } $ n = 3 ; $ k = 2 ; echo getSum ( $ n , $ k ) ; ? >


"Program to find the Area and Perimeter of a Semicircle | Function for calculating the area ; Formula for finding the area ; Function for calculating the perimeter ; Formula for finding the perimeter ; Get the radius ; Find the area ; Find the perimeter"
How can the above be solved in PHP?

 < ? php function area ( $ r ) { return ( 0.5 ) * ( 3.14 ) * ( $ r * $ r ) ; } function perimeter ( $ r ) { return ( 3.14 ) * ( $ r ) ; } $ r = 10 ; echo " The ▁ Area ▁ of ▁ Semicircle : ▁ " , area ( $ r ) , "
 " ; echo " The ▁ Perimeter ▁ of ▁ Semicircle : ▁ " , perimeter ( $ r ) , "
 " ; ? >


"Program to find the Area and Volume of Icosahedron | Function to find area of Icosahedron ; Formula to calculating area ; Function to find volume of Icosahedron ; Formula to calculating volume ; Driver Code ; Function call to find area of Icosahedron . ; Function call to find volume of Icosahedron ."
How can the above be solved in PHP?

 < ? php function findArea ( $ a ) { $ area ; $ area = 5 * sqrt ( 3 ) * $ a * $ a ; return $ area ; } function findVolume ( $ a ) { $ volume ; $ volume = ( ( float ) 5 / 12 ) * ( 3 + sqrt ( 5 ) ) * $ a * $ a * $ a ; return $ volume ; } $ a = 5 ; echo " Area : " ▁ , ▁ findArea ( $ a ) , ▁ " " ;
 echo ▁ " Volume : " ? >


"Program to find the Area of an Ellipse | Function to find area of an ellipse . ; formula to find the area of an Ellipse . ; Display the result ; Driver code"
How can the above be solved in PHP?

< ? php function findArea ( $ a , $ b ) { $ Area ; $ Area = 3.142 * $ a * $ b ; echo " Area : ▁ " . $ Area ; } $ a = 5 ; $ b = 4 ; findArea ( $ a , $ b ) ; ? >


"Program to find the Break Even Point | Function to calculate Break Even Point ; Calculating number of articles to be sold ; Driver Code"
How can the above be solved in PHP?

< ? php function breakEvenPoint ( $ exp , $ S , $ M ) { $ earn = $ S - $ M ; $ res = ceil ( $ exp / $ earn ) ; return $ res ; } $ exp = 3550 ; $ S = 90 ; $ M = 65 ; echo breakEvenPoint ( $ exp , $ S , $ M ) ; ? >


"Program to find the Circumcircle of any regular polygon | Function to find the radius of the circumcircle ; these cannot be negative ; Radius of the circumcircle ; Return the radius ; Driver code ; Find the radius of the circumcircle"
How can the above be solved in PHP?

< ? php function findRadiusOfcircumcircle ( $ n , $ a ) { if ( $ n < 0 $ a < 0 ) return -1 ; $ radius = $ a / sqrt ( 2 - ( 2 * cos ( 360 / $ n ) ) ) ; return $ radius ; } $ n = 5 ; $ a = 6 ; echo findRadiusOfcircumcircle ( $ n , $ a ) ; ? >


"Program to find the Hidden Number | Getting the size of array ; Getting the array of size n ; Solution ; Finding sum of the array elements ; Dividing sum by size n ; Print x , if found"
How can the above be solved in PHP?


"Program to find the Interior and Exterior Angle of a Regular Polygon | function to find the interior and exterior angle ; formula to find the interior angle ; formula to find the exterior angle ; Displaying the output ; Driver code ; Function calling"
How can the above be solved in PHP?

 < ? php function findAngle ( $ n ) { $ interiorAngle ; $ exteriorAngle ; $ interiorAngle = ( $ n - 2 ) * 180 / $ n ; $ exteriorAngle = 360 / $ n ; echo " Interior ▁ angle : ▁ " , $ interiorAngle , "
 " ; echo " Exterior ▁ angle : ▁ " , $ exteriorAngle ; } $ n = 10 ; findAngle ( $ n ) ; ? >


"Program to find the Nth Harmonic Number | Function to find N - th Harmonic Number ; H1 = 1 ; loop to apply the forumula Hn = H1 + H2 + H3 ... + Hn - 1 + Hn - 1 + 1 / n ; Driver Code"
How can the above be solved in PHP?

< ? php function nthHarmonic ( $ N ) { $ harmonic = 1.00 ; for ( $ i = 2 ; $ i <= $ N ; $ i ++ ) { $ harmonic += ( float ) 1 / $ i ; } return $ harmonic ; } $ N = 8 ; echo nthHarmonic ( $ N ) ; ? >


"Program to find the Nth number of the series 2 , 10 , 24 , 44 , 70. ... . | function to return Nth term of the series ; Taking n as 4 ; Get Nth term"
How can the above be solved in PHP?

< ? php function NthTerm ( $ n ) { $ mod = 1000000009 ; $ x = ( 3 * $ n * $ n ) % $ mod ; return ( $ x - $ n + $ mod ) % $ mod ; } let N = 4 ; echo NthTerm ( $ N ) ; ? >


"Program to find the Nth term of series 5 , 10 , 17 , 26 , 37 , 50 , 65 , 82 , ... | calculate Nth term of series ; return the final sum ; Driver Code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return pow ( $ n , 2 ) + 2 * $ n + 2 ; } $ N = 4 ; echo nthTerm ( $ N ) ;


"Program to find the Nth term of series 5 , 12 , 21 , 32 , 45. ... . . | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return pow ( $ n , 2 ) + 4 * $ n ; } $ N = 4 ; echo nthTerm ( $ N ) ; ? >


"Program to find the Nth term of series | calculate Nth term of series ; Get the value of N ; Find the Nth term and print it"
How can the above be solved in PHP?

< ? php function nthTerm ( $ N ) { return ( ( 3 * $ N * $ N ) - ( 6 * $ N ) + 2 ) ; } $ N = 3 ; echo nthTerm ( $ N ) ; ? >


"Program to find the Nth term of the series 0 , 14 , 40 , 78 , 124 , ... | calculate sum upto Nth term of series ; return the final sum ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return 6 * pow ( $ n , 2 ) - 4 * $ n - 2 ; } $ N = 4 ; echo nthTerm ( $ N ) ;


"Program to find the Nth term of the series 0 , 3 / 1 , 8 / 3 , 15 / 5. . ... ... | Function to return the nth term of the given series ; nth term ; Driver code"
How can the above be solved in PHP?

< ? php function Nthterm ( $ n ) { $ numerator = ( pow ( $ n , 2 ) ) -1 ; $ denomenator = 2 * $ n - 3 ; echo $ numerator , " / " , $ denomenator ; return $ Tn ; } $ n = 3 ; Nthterm ( $ n ) ; ? >


"Program to find the Nth term of the series 0 , 5 , 14 , 27 , 44 , ... ... . . | Calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return 2 * pow ( $ n , 2 ) - $ n - 1 ; } $ N = 4 ; echo nthTerm ( $ N ) ; ? >


"Program to find the Nth term of the series 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ... | calculate Nth term of series ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return 4 * pow ( $ n , 2 ) - 7 * $ n + 3 ; } $ N = 4 ; echo nthTerm ( $ N ) ; ? >


"Program to find the Nth term of the series 3 , 20 , 63 , 144 , 230 , â €¦ â €¦ | calculate Nth term of series ; return final sum ; Driver code"
How can the above be solved in PHP?

< ? php function nthTerm ( $ n ) { return 2 * pow ( $ n , 3 ) + pow ( $ n , 2 ) ; } $ N = 3 ; echo nthTerm ( $ N ) ; ? >


"Program to find the Nth term of the series 3 , 7 , 13 , 21 , 31. ... . | Function to calculate sum ; Return Nth term ; declaration of number of terms ; Get the Nth term"
How can the above be solved in PHP?

< ? php function getNthTerm ( $ N ) { return ( pow ( $ N , 2 ) + $ N + 1 ) ; } $ N = 11 ; echo getNthTerm ( $ N ) ; ? >


"Program to find the Radius of the incircle of the triangle | Function to find the radius of the incircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of the triangle ; Radius of the incircle ; Return the radius ; Get the sides of the triangle ; Find the radius of the incircle"
How can the above be solved in PHP?

< ? php function findRadiusOfIncircle ( $ a , $ b , $ c ) { if ( $ a < 0 $ b < 0 $ c < 0 ) return -1 ; $ p = ( $ a + $ b + $ c ) / 2 ; $ area = sqrt ( $ p * ( $ p - $ a ) * ( $ p - $ b ) * ( $ p - $ c ) ) ; $ radius = $ area / $ p ; return $ radius ; } $ a = 2 ; $ b = 2 ; $ c = 3 ; echo findRadiusOfIncircle ( $ a , $ b , $ c ) . " " ;


"Program to find the Roots of Quadratic equation | Prints roots of quadratic equation ax * 2 + bx + x ; If a is 0 , then equation is not quadratic , but linear ; d < 0 ; Driver code ; Function call"
How can the above be solved in PHP?

 < ? php function findRoots ( $ a , $ b , $ c ) { if ( $ a == 0 ) { echo " Invalid " ; return ; } $ d = $ b * $ b - 4 * $ a * $ c ; $ sqrt_val = sqrt ( abs ( $ d ) ) ; if ( $ d > 0 ) { echo " Roots ▁ are ▁ real ▁ and ▁ " . " different ▁
 " ; echo ( - $ b + $ sqrt_val ) / ( 2 * $ a ) , "
 " , ( - $ b - $ sqrt_val ) / ( 2 * $ a ) ; } else if ( $ d == 0 ) { echo " Roots ▁ are ▁ real ▁ and ▁ same ▁
 " ; echo - $ b / ( 2 * $ a ) ; } else { echo " Roots ▁ are ▁ complex ▁
 " ; echo - $ b / ( 2 * $ a ) , " ▁ + ▁ i " , $ sqrt_val , "
 " , - $ b / ( 2 * $ a ) , " ▁ - ▁ i " , $ sqrt_val ; } } $ a = 1 ; $ b = -7 ; $ c = 12 ; findRoots ( $ a , $ b , $ c ) ; ? >


"Program to find the Volume of an irregular tetrahedron | Function to find the volume ; Steps to calculate volume of a Tetrahedron using formula ; edge lengths"
How can the above be solved in PHP?

< ? php function findVolume ( $ u , $ v , $ w , $ U , $ V , $ W , $ b ) { $ uPow = pow ( $ u , 2 ) ; $ vPow = pow ( $ v , 2 ) ; $ wPow = pow ( $ w , 2 ) ; $ UPow = pow ( $ U , 2 ) ; $ VPow = pow ( $ V , 2 ) ; $ WPow = pow ( $ W , 2 ) ; $ a = 4 * ( $ uPow * $ vPow * $ wPow ) - $ uPow * pow ( ( $ vPow + $ wPow - $ UPow ) , 2 ) - $ vPow * pow ( ( $ wPow + $ uPow - $ VPow ) , 2 ) - $ wPow * pow ( ( $ uPow + $ vPow - $ WPow ) , 2 ) + ( $ vPow + $ wPow - $ UPow ) * ( $ wPow + $ uPow - $ VPow ) * ( $ uPow + $ vPow - $ WPow ) ; $ vol = sqrt ( $ a ) ; $ vol /= $ b ; echo $ vol ; } $ u = 1000 ; $ v = 1000 ; $ w = 1000 ; $ U = 3 ; $ V = 4 ; $ W = 5 ; $ b = 12 ; findVolume ( $ u , $ v , $ w , $ U , $ V , $ W , $ b ) ; ? >


"Program to find the common ratio of three numbers | Utility function ; Function to print a : b : c ; To print the given proportion in simplest form . ; Get the ratios Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c"
How can the above be solved in PHP?


"Program to find the count of coins of each type from the given ratio | function to calculate coin ; Converting each of them in rupees . As we are given totalRupees = 1800 ; Driver Code"
How can the above be solved in PHP?

 < ? php function coin ( $ totalRupees , $ X , $ Y , $ Z ) { $ one = 0 ; $ fifty = 0 ; $ twentyfive = 0 ; $ result = 0 ; $ total = 0 ; $ one = $ X * 1 ; $ fifty = ( ( $ Y * 1 ) / 2.0 ) ; $ twentyfive = ( ( $ Z * 1 ) / 4.0 ) ; $ total = $ one + $ fifty + $ twentyfive ; $ result = ( ( $ totalRupees ) / $ total ) ; return $ result ; } $ totalRupees = 1800 ; $ X = 1 ; $ Y = 2 ; $ Z = 4 ; $ Rupees = coin ( $ totalRupees , $ X , $ Y , $ Z ) ; echo "1 ▁ rupess ▁ coins ▁ = ▁ " , $ Rupees * 1 , "
 " ; echo "50 ▁ paisa ▁ coins ▁ = ▁ " , $ Rupees * 2 , "
 " ; echo "25 ▁ paisa ▁ coins ▁ = ▁ " , $ Rupees * 4 , "
 " ; ? >


"Program to find the last digit of X in base Y | Function to find the last digit of X in base Y ; Driver code"
How can the above be solved in PHP?

< ? php function last_digit ( $ X , $ Y ) { echo ( $ X % $ Y ) ; } $ X = 55 ; $ Y = 3 ; last_digit ( $ X , $ Y ) ; ? >


"Program to find the maximum difference between the index of any two different numbers | Function to return the maximum difference ; Iteratively check from back ; Different numbers ; Iteratively check from the beginning ; Different numbers ; Driver code"
How can the above be solved in PHP?


"Program to find the minimum ( or maximum ) element of an array | PHP program to find minimum ( or maximum ) element in an array . ; Driver Code"
How can the above be solved in PHP?

 < ? php function getMin ( & $ arr , $ n ) { return min ( $ arr ) ; } function getMax ( & $ arr , $ n ) { return max ( $ arr ) ; } $ arr = array ( 12 , 1234 , 45 , 67 , 1 ) ; $ n = sizeof ( $ arr ) ; echo " Minimum ▁ element ▁ of ▁ array : ▁ " . getMin ( $ arr , $ n ) . "
 " ; echo " Maximum ▁ element ▁ of ▁ array : ▁ " . getMax ( $ arr , $ n ) ; ? >


"Program to find the nth Kynea number | Function to calculate nth kynea number ; Calculate nth kynea number ; Driver Code ; print nth kynea number"
How can the above be solved in PHP?

< ? php function nthKyneaNumber ( $ n ) { return ( ( 1 << ( 2 * $ n ) ) + ( 1 << ( $ n + 1 ) ) - 1 ) ; } $ n = 2 ; echo nthKyneaNumber ( $ n ) ; ? >


"Program to find the nth Kynea number | Function to calculate nth kynea number ; Firstly calculate 2 ^ n + 1 ; Now calculate ( 2 ^ n + 1 ) ^ 2 ; Now calculate ( ( 2 ^ n + 1 ) ^ 2 ) - 2 ; return nth Kynea number ; Driver Code ; print nth kynea number"
How can the above be solved in PHP?

< ? php function nthKyneaNumber ( $ n ) { $ n = ( 1 << $ n ) + 1 ; $ n = $ n * $ n ; $ n = $ n - 2 ; return $ n ; } $ n = 8 ; echo nthKyneaNumber ( $ n ) ;


"Program to find the number of region in Planar Graph | Function to return the number of regions in a Planar Graph ; Driver code"
How can the above be solved in PHP?

< ? php function Regions ( $ Vertices , $ Edges ) { $ R = $ Edges + 2 - $ Vertices ; return $ R ; } $ V = 5 ; $ E = 7 ; echo ( Regions ( $ V , $ E ) ) ; ? >


"Program to find the percentage of difference between two numbers | Function to calculate the percentage ; Driver Code ; Function calling"
How can the above be solved in PHP?

< ? php function percent ( $ a , $ b ) { $ result = 0 ; $ result = ( ( $ b - $ a ) * 100 ) / $ a ; return $ result ; } $ a = 20 ; $ b = 25 ; echo percent ( $ a , $ b ) . " % " ; ? >


"Program to find the product of ASCII values of characters in a string | Function to find product of ASCII value of characters in string ; Traverse string to find the product ; Return the product ; Driver code"
How can the above be solved in PHP?

< ? php function productAscii ( $ str ) { $ prod = 1 ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { $ prod *= ord ( $ str [ $ i ] ) ; } return $ prod ; } $ str = " GfG " ; echo productAscii ( $ str ) ; ? >


"Program to find the profit or loss when CP of N items is equal to SP of M items | Function to calculate Profit or loss ; Driver Code"
How can the above be solved in PHP?

< ? php function profitLoss ( $ N , $ M ) { if ( $ N == $ M ) echo " No ▁ Profit ▁ nor ▁ Loss " ; else { $ result = 0.0 ; $ result = ( abs ( $ N - $ M ) ) / $ M ; if ( $ N - $ M < 0 ) echo " Loss ▁ = ▁ - " , $ result * 100 , " % " ; else echo " Profit ▁ = ▁ " , $ result * 100 , " % " ; } } $ N = 8 ; $ M = 9 ; profitLoss ( $ N , $ M ) ; ? >


"Program to find the quantity after mixture replacement | Function to calculate the Remaining amount . ; calculate Right hand Side ( RHS ) . ; calculate Amount left by multiply it with original value . ; Driver Code"
How can the above be solved in PHP?

< ? php function Mixture ( $ X , $ Y , $ Z ) { $ result = 0.0 ; $ result1 = 0.0 ; $ result1 = ( ( $ X - $ Y ) / $ X ) ; $ result = pow ( $ result1 , $ Z ) ; $ result = $ result * $ X ; return $ result ; } $ X = 10 ; $ Y = 2 ; $ Z = 2 ; echo Mixture ( $ X , $ Y , $ Z ) , " ▁ litres " ; ? >


"Program to find the rate percentage from compound interest of consecutive years | Function to return the required rate percentage ; Driver code"
How can the above be solved in PHP?


"Program to find the side of the Octagon inscribed within the square | Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Get he square side ; Find the side length of the square"
How can the above be solved in PHP?

< ? php function octaside ( $ a ) { if ( $ a < 0 ) return -1 ; $ s = $ a / ( sqrt ( 2 ) + 1 ) ; return $ s ; } $ a = 4 ; echo octaside ( $ a ) ; ? >


"Program to find the smallest element among three elements | PHP implementation to find the smallest of three elements"
How can the above be solved in PHP?

< ? php $ a = 5 ; $ b = 7 ; $ c = 10 ; if ( $ a <= $ b && $ a <= $ c ) echo $ a . " ▁ is ▁ the ▁ smallest " ; else if ( $ b <= $ a && $ b <= $ c ) echo $ b . " ▁ is ▁ the ▁ smallest " ; else echo $ c . " ▁ is ▁ the ▁ smallest " ;


"Program to find the sum of the series 23 + 45 + 75 + ... . . upto N terms | calculate Nth term of series ; Get the value of N ; Get the sum of the series"
How can the above be solved in PHP?


"Program to find the surface area of the square pyramid | function to find the surface area ; Driver Code ; surface area of the square pyramid"
How can the above be solved in PHP?

< ? php function surfaceArea ( $ b , $ s ) { return 2 * $ b * $ s + pow ( $ b , 2 ) ; } $ b = 3 ; $ s = 4 ; echo surfaceArea ( $ b , $ s ) ; ? >