Server Side Programming Articles - Page 1992 of 2650

Find square root of number upto given precision using binary search in C++

Farhan Muhamed
Updated on 04-Aug-2025 19:02:57

2K+ Views

In this article, we will learn how to find the square root of a number up to a given precision by using binary search algorithm and implement it in C++. Before dive into the concept, make sure that you have a basic understanding of binary search algorithm. Square Root of a Number Upto a Given Precision In this problem, you are given a positive floating point number N and a positive integer P. The task is to find the square root of N up to P decimal places using binary search. Scenario 1 Input: N = ... Read More

Find smallest values of x and y such that ax – by = 0 in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:10:27

163 Views

Suppose we have two values a and b. We have to find x and y, such that ax – by = 0. So if a = 25 and b = 35, then x = 7 and y = 5.To solve this, we have to calculate the LCM of a and b. LCM of a and b will be the smallest value that can make both sides equal. The LCM can be found using GCD of numbers using this formula −LCM (a,b)=(a*b)/GCD(a,b)Example Live Demo#include #include using namespace std; void getSmallestXY(int a, int b) {    int lcm = (a * b) / __gcd(a, b);    cout

destroy() method in Tkinter - Python

Pradeep Elance
Updated on 19-Dec-2019 12:19:04

5K+ Views

The destroy() method in Tkinter destroys a widget. It is useful in controlling the behavior of various widgets which depend on each other. Also when a process is complete by some user action we need to destroy the GUI components to free the memory as well as clear the screen. The destroy() method achieves all this.In the below example we have screen with 3 buttons. Clicking the first button closes the window itself where as the clicking of the second button closes the 1st button and so on. This behavior is emulated by using the destroy method as shown in ... Read More

Find smallest subarray that contains all elements in same order in C++

Arnab Chakraborty
Updated on 19-Dec-2019 12:07:10

374 Views

Suppose we have two arrays of size m and n, The task is to find minimum length subarray in the first array, that contains all the elements if the second array. Element in second array may be present in the large array in non-contiguous but order must be same. So if two arrays are like A = [2, 2, 4, 5, 8, 9], and B = [2, 5, 9], then the output will be 5. As the smallest subarray of A, will be [2, 4, 5, 8, 9]. Here all elements like [2, 5, 9] are in the same order. ... Read More

Find the Nth term of the series where each term f[i] = f[i – 1] – f[i – 2] in C++

Arnab Chakraborty
Updated on 19-Dec-2019 11:42:16

136 Views

Suppose we have a series called f. Each term of f, follows this rule f[i] = f[i – 1] – f[i – 2], we have to find the Nth term of this sequence. f[0] = X and f[1] = Y. If X = 2 and Y = 3, and N = 3. The result will be -2.If we see this closely, there will be almost six terms before the sequence starts repeating itself. So we will find the first 6 terms of the series and then the Nth term will be the same as (N mod 6)th term.Example#include< iostream> using ... Read More

Find the last digit when factorial of A divides factorial of B in C++

Arnab Chakraborty
Updated on 19-Dec-2019 11:37:38

186 Views

If we have two integers A and B, and B >= A, we have to compute the last digit of the B! / A! When the value of A = 2 and B = 4, then result is 2, 2! = 2 and 4! = 24, so 24/2 = 12. the last digit is 2.As we know that the last digit of factorial will be in set {0, 1, 2, 4, 6}, then follow these steps to solve this problem −We will find the difference between A and Bif diff >=5, then answer is 0otherwise, iterate from (A + 1) ... Read More

Create a stopwatch using python

Pradeep Elance
Updated on 19-Dec-2019 11:40:26

1K+ Views

A stopwatch is used to measure the time interval between two events usually in seconds to minutes. It has various usage like in sports or measuring the flow of heat, current etc in an industrial setup. Python can be used to creat a stopwatch by using its tkinter library.This library will have the GUI features to create a stopwatch showing the  Start, Stop and Reset  option. The key component of the program is using the lable.after()  module of tkinter.label.after(parent, ms, function = None) where parent: The object of the widget which is using this function. ms: Time in miliseconds. function: ... Read More

Count set bits using Python List comprehension

Pradeep Elance
Updated on 19-Dec-2019 11:34:21

190 Views

Set bits are the bits representing 1 in the binary form of a number. In this article we will see how to count the number of set bits in a given decimal number.#53 in binary is: 110101 The number of set bits is the number of ones. Here it is 4.In the below program we take the number and convert it to binary. As the binary conversion contains 0b as the first two characters, we remove it using string splitting technique. Then use a for loop to count each bit of the binary number if that value of the digit ... Read More

Find the K-th minimum element from an array concatenated M times in C++

Arnab Chakraborty
Updated on 19-Dec-2019 11:35:33

152 Views

Consider we have an array A, and another two integers K and M. We have to find Kth minimum element after concatenating the array to itself M number of times. Suppose the array is like A = [3, 1, 2], K = 4 and M = 3, so after concatenating A, 3 times, it will be [3, 1, 2, 3, 1, 2, 3, 1, 2], the 4th smallest element is 2 here.To solve this problem, we will sort the array A, then return the value, present at index ((K – 1)/M), of the array.Example Live Demo#include #include using namespace std; int ... Read More

Find the Diameter or Longest chord of a Circle in C++

Arnab Chakraborty
Updated on 19-Dec-2019 11:25:00

137 Views

Suppose we have radius r is given. We have to find the diameter or longest chord of the circle. If the radius is 9, and diameter will be 18. This task is extremely simple, we have to find the 2*r, that is the diameter of the circle.Example Live Demo#include using namespace std; int getDiameter(int r) {    return 2*r; } int main() {    int r = 9;    cout

Advertisements