Server Side Programming Articles - Page 1742 of 2650

PHP base_convert() Function

Malhar Lathkar
Updated on 29-Jun-2020 08:31:54

516 Views

Definition and UsageThe base_convert() function is versatile utility to convert a number with one base to another. The base is not restricted to binary, octal, hexadecimal or decimal. It can be any number between 2 and 36.First argument to this function is a string that can contain alpha-numeric characters. Digits in a number with base>9 will be represented by alphabets a - z such that 10 is represented by 'a', 11 by 'b' upto 35 by 'z'For example base_convert('1001', 2, 10) converts '1001' from binary to decimal number which is 9Syntaxbase_convert ( string $number , int $frombase , int $tobase ... Read More

PHP atanh() Function

Malhar Lathkar
Updated on 29-Jun-2020 08:29:17

224 Views

Definition and UsageThe atanh() function returns the inverse hyperbolic tangent ratio of given given parameter. In other words, the return value of atanh() is hyperbolic tangent of given parameter. A inverse hyperbolic tangent function is defined as .atanh(x) = 0.5Xlog((1+x)/(1-x))This function returns a float value .Syntaxatanh ( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point value whose inverse hyperbolic tangent is to be calculatedReturn ValuesPHP atanh() function returns inverse hyperbolic tangent ratio of given parameter.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculates atanh(pi/4) and returns which is also ... Read More

PHP atan2() Function

Malhar Lathkar
Updated on 29-Jun-2020 08:29:52

253 Views

Definition and UsageThe atan2() function calculates arc tan of two variablesatan2(y, x) returns the arc tangent of the two numbers x and y. although it is similar to atan(y)/atan(x), the signs of both x and y are used to determine the quadrant of the result. Accordingly for values of x and y atan2() isatan(y/x) if x>0atan(y/x)+pi if x>0atan(y/x)-pi if xOutputThis will produce following result −atan2(5, -5) = 2.3561944901923Example Live DemoFollowing program computes atan2(5, 0) and returns 1.570796326795 (M_PI_2) −OutputThis will produce following result −atan2(5, 0) = 1.5707963267949Example Live DemoFollowing example computes atan2(0, 0) and returns 0OutputThis will produce following result −atan2(0, 0) ... Read More

PHP atan() Function

Malhar Lathkar
Updated on 29-Jun-2020 08:24:18

281 Views

Definition and UsageThe atan() function returns the arc tan or tan inverse of arg in radians. atan() is the inverse function of tan(). Therefore if tan(x)=y, atan(y)=x.For example, tan(pi/3)= 1.73205080757 (Squre Root of 3) and atan(1.73205080757)=1.04719755 rad which is equal to pi/3.This function returns a float value .Syntaxatan ( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point number whose arc tan is to be calculated.Return ValuesPHP atan() function returns arc tan of given number. It is angle represented in radians. Returned value is between -pi/2 and pi/2PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well ... Read More

PHP asinh() Function

Malhar Lathkar
Updated on 29-Jun-2020 08:22:30

242 Views

Definition and UsageThe asinh() function calculates inverse of hyperbolic sine of given parameter. In other words, the return value of asinh() is hyperbolic sine of given parameter. A inverse hyperbolic sine function is defined asasinh(x) = log(x+sqrt(pow(x, 2)+1))This function returns a float value.Syntaxasinh( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point value whose inverse hyperbolic sine is to be calculatedReturn ValuesPHP asinh() function returns inverse hyperbolic sine ratio of given parameter.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculates asinh(pi/2) which we can verify using the definition −OutputThis will ... Read More

Image Smoother in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:21:54

416 Views

Suppose we have a 2D matrix M representing the gray scale of an image, we have to design a smoother to make the gray scale of each pixel becomes the average gray scale (rounding down) of all the 8 surrounding pixels and itself. If a cell has less than 8 surrounding cells, convert all possible pixels.So, if the input is like111101111then the output will be000000000To solve this, we will follow these steps −R := row count of MC := column count ofDefine an array d = { -1, 0, 1 }Define one 2D array res of size (R x C)for ... Read More

Robot Return to Origin in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:18:04

355 Views

Suppose there is a robot and its starting position is (0, 0). If we have a sequence of its movements, we have to check whether this robot ends up at (0, 0) after it completes its moves.The move sequence is given as a string, and the character moves[i] represents its ith move. Symbols are R for right, L for left, U for up, and D for down. If the robot returns to the origin after it finishes all of its moves, return true. Otherwise, return false.So, if the input is like "RRULLD", then the output will be true, Right two-unit, ... Read More

Two Sum IV - Input is a BST in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:16:29

208 Views

Suppose we have a Binary Search Tree and one target value; we have to check whether there exist two elements in the BST such that their sum is equal to the given target or not.So, if the input is likethen the output will be True.To solve this, we will follow these steps −Define an array vDefine a function inorder(), this will take root, if root is null, then −returninorder(left of root)insert value of root into vinorder(left of root)Define a function findnode(), this will take k, n := size of vwhile i < j, do −t := v[i] + v[j]if t ... Read More

Set Mismatch in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:13:29

288 Views

Suppose there is a set S that is originally containing numbers from 1 to n. But unfortunately, due to some error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.Now if we have an array called nums that is representing the data status of this set after the error. Our task is to find the number occurs twice and then find the number that is missed. return the results in the form of an array.So, if the input is like [1, 2, ... Read More

Maximum Average Subarray I in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:10:35

199 Views

Suppose we have an array with n elements, we have to find the contiguous subarray of given length k that has the maximum average value. We have to return the maximum average value.So, if the input is like [1, 13, -5, -8, 48, 3] and k = 4, then the output will be 12.0, as (13-5-8+48)/4 = 12.0.To solve this, we will follow these steps −sum := 0for initialize i := 0, when i < k, update (increase i by 1), do −sum := sum + nums[i]maxi := sumfor initialize i := k, when i < size of nums, update ... Read More

Advertisements