Server Side Programming Articles

Page 1826 of 2109

Find value of y mod (2 raised to power x) in C++

sudhir sharma
sudhir sharma
Updated on 01-Feb-2022 268 Views

In this problem, we are given two values x and y. Our task is to find value of y mod (2 raised to power x).Let's take an example to understand the problem, Input : x = 2, y = 19 Output : 3Explanation −y % 2x = 19 % 22 = 19 % 4 = 3 Solution ApproachA simple solution to the problem is by directly calculating the value of 2x using the pow() function and then finding the value of y % 2x.Another approach to solve the problem is by using log. For the value of y < 2x, ...

Read More

Find value of k-th bit in binary representation in C++

sudhir sharma
sudhir sharma
Updated on 01-Feb-2022 489 Views

In this problem, we are given two values n and k. Our task is to find value of k-th bit in binary representation.Let's take an example to understand the problem, Input : n= 5, k = 2 Output : 0Explanation −Binary of 5 = 0101 Second LSB bit is 0.Solution ApproachA solution to the problem is by performing bitwise AND of the binary conversion of the number N with a number with all bits unset and one bit set which is at kth position, to get the result.ExampleProgram to illustrate the working of our solution, #include using namespace std; ...

Read More

Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n in C++

sudhir sharma
sudhir sharma
Updated on 01-Feb-2022 277 Views

In this problem, we are given a value n. Our task is to find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n.Let's take an example to understand the problem, Input : n= 5 Output : 0Explanation −(51 + 52 + 53 + 54) mod 5 = (5 + 25 + 125 + 625) mod 5 = (780) mode 5 = 0Solution ApproachA simple solution to the problem is by directly finding the value of the equation for the given value of N and then calculating its modulus with 5.ExampleProgram to illustrate the working of ...

Read More

First element that appears even number of times in an array in C++

sudhir sharma
sudhir sharma
Updated on 01-Feb-2022 340 Views

In this problem, we are given an array arr[] consisting of N integer values. Our task is to create a program for finding the first element that appears even number of times in an array. If any element exists that satisfies the condition return it otherwise return -1 denoting false.Let's take an example to understand the problem, Input: arr[] = {2, 3, 7, 2, 3, 6, 4, 1, 2} Output: 3Solution ApproachA simple method to solve the problem is by considering each element of the array one by one and then checking the element's occurrence frequency even and returning the ...

Read More

Frugal Number in C++

sudhir sharma
sudhir sharma
Updated on 01-Feb-2022 199 Views

In this problem, we are given a positive integer N. Our task is to create a program to check whether the given number is a Frugal number or not.FRUGAL NUMBER − A number whose number of digits is strictly greater than the number of digits in the prime factorization of the given number.Example − 625, prime factors of number 625 is 54.The number of digits in 625 is 3.The number of digits in 54 is 2.3 is strictly greater than 2. Hence, 625 is a frugal number.First few frugal number are − 125, 128, 243, 256, 343, 512, 625, etc.Let’s ...

Read More

Flatten a multilevel linked list in C++

sudhir sharma
sudhir sharma
Updated on 31-Jan-2022 620 Views

In this problem, we are given a multilevel linked list. Our task is to create a program to flatten a multilevel linked list.The flattening operation is done in such a way that the first level nodes will occur first in the linked list and then the second level nodes will occur.Multilevel linked list is a multi-dimensional data structure in which every node of the linked list has two link pointers, one a link to the next node and one to the child list with one or more nodes. This child pointer may or may not point to other list nodes.ExampleLet’s ...

Read More

Fizz Buzz Implementation in C++

sudhir sharma
sudhir sharma
Updated on 31-Jan-2022 6K+ Views

In this problem, we will see the implementation and types of Fizz-Bizz problem.Fizz Buzz − it is a simple programming problem in which the programmer changes the occurrence o all multiples of 3 by ‘Fizz’ and all multiples of 5 by ‘Buzz’ in the numbers from 1 to 100.Let’s take an example to understand the problem1, 2, 'Fizz', 4, 'Buzz', 'Fizz' , 7, 8, 'Fizz' , 'Buzz', 11, 'Fizz' , 13, 14, 'Fizz Buzz' , 16, 17, 'Fizz' , 19, 'Buzz', ....Solution ApproachA simple approach to solving the problem is by simply using a loop from 1 to 100. And ...

Read More

Fitting Shelves Problem in C++

sudhir sharma
sudhir sharma
Updated on 31-Jan-2022 440 Views

In this problem, we are given three integer values W, n, m denoting the length of wall W, size of shelves n, and m. Our task is To Create a Program to solve the Fitting Shelves Problem.We need to find a way to fit shelves in such a way that the space left after fitting shelves is minimized. A secondary constrain while solving is the cost of making, the larger shelves are more cost-effective so, we need to give them a priority.The output should be in the following form, Number of n size shelves number of m size shelves space ...

Read More

req.method Property in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 1K+ Views

The req.method property contains a string that corresponds to the HTTP methods of the request which are GET, POST, PUT, DELETE, and so on...These methods are based upon the requests sent by the user. All the above methods have different use-cases.Syntaxreq.methodExample 1Create a file with the name "reqMethod.js" and copy the following code snippet. After creating the file, use the command "node reqMethod.js" to run this code as shown in the example below −// req.method Property Demo Example // Importing the express & cookieParser module var cookieParser = require('cookie-parser'); var express = require('express'); // Initializing the express and ...

Read More

res.attachment() Method in Express.js

Mayank Agarwal
Mayank Agarwal
Updated on 29-Jan-2022 1K+ Views

The res.attachment() method is used for setting the Content-Disposition header field to "attachment". If a filename is passed, then it sets the Content-type based on the extension name that is retrieved from the res.type(). It sets the Content-Disposition "filename" field with the parameter.Syntaxres.attachment()Example 1Create a file with the name "resAttachment.js" and copy the following code snippet. After creating the file, use the command "node resAttachment.js" to run this code as shown in the example below −// res.attachment() Method Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = ...

Read More
Showing 18251–18260 of 21,090 articles
Advertisements