Server Side Programming Articles - Page 568 of 2650

C++ program to find fourth side of a quadrilateral

Arnab Chakraborty
Updated on 03-Mar-2022 07:24:58

286 Views

Suppose we have three numbers a, b and c. We want to make a closed fence in a shape of arbitrary non-degenerate simple quadrilateral. We already have three sides of length a, b and c. We have to find another side d.So, if the input is like a = 12; b = 34; c = 56, then the output will be 42, other answers are also possible.StepsTo solve this, we will follow these steps −return a + b + c - 2ExampleLet us see the following implementation to get better understanding −#include using namespace std; int solve(int a, int ... Read More

C++ program to count expected number of operations needed for all node removal

Arnab Chakraborty
Updated on 03-Mar-2022 07:28:50

204 Views

Suppose we have the adjacency matrix of a directed graph G. Until the graph becomes empty, we are repeating the following operation: Select one vertex from G, then erase that vertex and all vertices that are reachable from that vertex by following some edges. Erasing a vertex will also erase the edges incident to it. We have to find the expected number of times the operation is doneSo, if the input is likethen the output will be 1.6667, because initially select vertex A, remove all vertices, if we select vertex B, remove B and C, and in second operation select ... Read More

Python – numpy.meshgrid

Syed Abeed
Updated on 03-Mar-2022 07:28:05

910 Views

numpy.meshgrid() is used to return coordinate matrices from coordinate vectors. Its syntax is as follows −numpy.meshgrid(*xi, **kwargs)ParametersMeshgrid can accept the following parameters −x1, x2, …, xn − It represents the coordinates of a grid.indexing − It is an optional parameter which defines the Cartesian 'xy' by default and matrix 'ij' index of output.sparse − It is an optional parameter. If we like to use sparse grid for conserving memory, then we have to set this parameter to True. By default, it is False.copy − It returns a copy of the original array for conversing memory when the parameter is True. ... Read More

C++ program to count number of dodecagons we can make of size d

Arnab Chakraborty
Updated on 03-Mar-2022 07:22:22

148 Views

Suppose we have a number d. Consider there is an infinite number of square tiles and regular triangular tiles with sides length 1. We have to find in how many ways we can form regular dodecagon (12-sided polygon) with sides d using these tiles. If the answer is too large, return result mod 998244353.StepsTo solve this, we will follow these steps−b := floor of d/2 - 1 c := 1 for initialize i := 2, when i < d, update (increase i by 1), do:    b := b * (floor of d/2)    c := c * i return ... Read More

C++ program to find range whose sum is same as n

Arnab Chakraborty
Updated on 03-Mar-2022 07:22:36

203 Views

Suppose we have a number n. We need to find two integers l and r, such that l < r and l + (l + 1) + ... + (r - 1) + r = n.So, if the input is like n = 25, then the output will be l = -2 and r = 7, because (−2) + (−1) + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 = 25. Other answers are also possible.StepsTo solve this, we will follow these steps −return -(n-1) and nExampleLet us see the following implementation to get better understanding −#include using namespace std; void solve(int n){    cout

C++ program to find circumference of the circular pond with radius R

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:43

121 Views

Suppose we have a number R, represents the radius of a pond. We have to find the circumference of this pond.So, if the input is like R = 73, then the output will be 458.67252742410977361942StepsTo solve this, we will follow these steps −res := r * 2 * cos-inverse (-1) return resLet us see the following implementation to get better understandingExampleLet us see the following implementation to get better understanding −#include using namespace std; double solve(int r){    double res = r * 2 * acos(-1);    return res; } int main(){    int R = 73;    cout

Python – numpy.reshape

Syed Abeed
Updated on 03-Mar-2022 07:19:58

502 Views

numpy.reshape() gives a new shape to an array without changing its data. Its syntax is as follows −numpy.reshape(arr, newshape, order='C')Parametersnumpy.reshape() can accept the following parameters −arr − Input array.shape − endpoint of the sequencenewshape − If an integer, then the result it will be a 1-D array of that length, and one dimension can be -1.order − It defines the order in which the input array elements should be read.If the order is ‘C’, then it reads and writes the elements which are using a C-like index order where the last index changes the fastest and the first axis index ... Read More

C++ program to convert kth character to lowercase

Arnab Chakraborty
Updated on 03-Mar-2022 07:15:49

216 Views

Suppose we have a string S with N characters. S contains only three types of characters 'A', 'B' or 'C'. We also have another integer K. We have to print S after lowercasing the Kth character in it.So, if the input is like K = 2; S = "AABACC", then the output will be "AaBACC"StepsTo solve this, we will follow these steps −S[K - 1] = S[K - 1] + 32 return SExampleLet us see the following implementation to get better understanding −#include using namespace std; string solve(int K, string S){    S[K - 1] = S[K - ... Read More

C++ program to find string after adding character 'a' string becomes non-palindrome

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:30

161 Views

Suppose we have a string S with lowercase English letters. We must insert exactly one character 'a' in S. After inserting that if we can make S not a palindrome then return that string, otherwise return "impossible".So, if the input is like S = "bpapb", then the output will be "bpaapb"StepsTo solve this, we will follow these steps −if concatenation of S and "a" is not palindrome, then:    return S concatenation 'a' otherwise when concatenation of "a" + S is not palindrome, then:    return 'a' concatenation S Otherwise    return "Impossible"ExampleLet us see the following implementation to get ... Read More

Python – numpy.geomspace

Syed Abeed
Updated on 03-Mar-2022 07:14:26

555 Views

numpy.geomspace() returns a set of numbers spaced evenly on a log scale (a geometric progression).Linspace − It is similar to geomspace, but endpoints specified using the log and base.Logspace − It is similar to geomspace, but endpoints specified with arithmetic instead of geometric progression.Syntaxnumpy.goemspace(start, stop, num = 50, endpoint = True/False, dtype = None)ParametersThe above function can accept the following parameters −start − Start of the sequence; default is zero.stop − Endpoint of the sequence.num − Number of elements which are generated between the start and stop sequence.endpoint − It controls whether the stop value is included in the output ... Read More

Advertisements