Found 33676 Articles for Programming

PHP atan() Function

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

274 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

236 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

408 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

342 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

201 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

276 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

187 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

Average of Levels in Binary Tree in C++

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

204 Views

Suppose we have a non-empty binary tree; we have to find the average value of the nodes on each level in the return the average values as an array.So, if the input is likethen the output will be [3, 14.5, 11].To solve this, we will follow these steps −Define an array resultDefine one queue qinsert root into qwhile (not q is empty), do −n := size of qDefine an array tempwhile n is non-zero, do −t := first element of qinsert value of t into tempdelete element from qif left of t is not null, then −insert left of t ... Read More

Sum of Square Numbers in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:05:53

1K+ Views

Suppose we have a non-negative integer c, we have to decide whether there're two integers a and b such that it satisfies a^2 + b^2 = c.So, if the input is like 61, then the output will be True, as 61 = 5^2 + 6^2.To solve this, we will follow these steps −Define a function isPerfect(), this will take x, sr := square root of xreturn true when (sr - floor of sr) is 0From the main method do the following, if c is same as 0, then −return truefor initialize i := 0, when i < the ceiling of ... Read More

Maximum Product of Three Numbers in C++

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

801 Views

Suppose we have an integer array; we have to find three numbers whose product is maximum then return the maximum product.So, if the input is like [1, 1, 2, 3, 3], then the output will be 18, as the three elements are [2, 3, 3].To solve this, we will follow these steps −sort the array numsl := size of numsa := nums[l - 1], b := nums[l - 2], c := nums[l - 3], d := nums[0], e := nums[1]return maximum of a * b * c and d * e * aExample Let us see the following implementation to get ... Read More

Advertisements