Hafeezul Kareem has Published 328 Articles

First digit in product of an array of numbers in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 11:06:13

164 Views

In this tutorial, we are going to learn how to find first digit of the product of an array.Let's see the steps to solve the problem.Initialize the array.Find the product of the elements in the array.Divide the result until it's less than 10.Print the single-digitExampleLet's see the code. Live Demo#include ... Read More

First digit in factorial of a number in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 11:04:26

146 Views

In this tutorial, we are going to write a program the finds the first digit of a factorial. Let's see an example.Input − 7Output − 5Let's see the steps to solve the problem.Initialize the numberFind the factorial of the number.Divide the number until it becomes a single digit.ExampleLet's see the ... Read More

Finding the vertex, focus and directrix of a parabola in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 11:02:50

170 Views

In this tutorial, we are going to learn how to find the vertex, focus, and directrix of a parabola. We are given constants of the parabola equation x, y, and z.There are straightforward formulas to find the vertex, focus, and directrix. Let's them.Vertex − (-y/2x, 4xz-y^2/4x)Focus − (-y/2x, 4xz-y^2+1/4x)Directrix − ... Read More

Finding the Parity of a number Efficiently in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 11:01:23

3K+ Views

In this tutorial, we are going to write a program that finds the parity of a number.We can find the parity of a number efficiently by performing the following operations using xor and right-shift operators.int b; b = n ^ (n >> 1); b = b ^ (b >> 2); ... Read More

Finding sum of digits of a number until sum becomes single digit in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 10:59:58

9K+ Views

In this tutorial, we are going to write a program that sums digits of the given number until it becomes a single digit. Let's see an example.Input −4543Output −7Let's see the steps to solve the problem.Initialize a number.Initialize the sum to 0.Iterate until the sum is less than 9.Add each digit of ... Read More

Finding ‘k’ such that its modulus with each array element is same in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 10:58:00

377 Views

In this tutorial, we are going to write a program that finds a number such that its modulus with each array element is same. Let's see an example.Input − arr = {10, 4, 2}Output − 1 2If there are two numbers x, y and x > y, assume that x ... Read More

Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d) in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 10:55:18

97 Views

In this tutorial, we are going to write a program that calculates ∆ X value that satisfies the given equation. The equation is (a + ∆ X)/(b + ∆ X) = c/d.Here, we need a little bit of math to solve the equation. And it's straightforward. Cross multiply and take ... Read More

Find zeroes to be flipped so that number of consecutive 1’s is maximized in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 10:51:19

118 Views

In this tutorial, we are going to find the zeroes count that need to be flipped to get maximum number of consecutive 1's in the array.We are going to use the sliding window approach to solve the problem. Let's see the steps to solve the problem.Initialize the array and max ... Read More

Find winner of an election where votes are represented as candidate names in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 10:49:34

767 Views

In this tutorial, we are going to write a program that finds the election winner. We will have an array of votes that each candidate got in the election. Let's see an example.Input {"A", "B", "C", "B", "A", "C", "D", "D", "A", "B", "D", "B", "A", "C", "D"}Output AHere, A and B ... Read More

Find ways an Integer can be expressed as sum of n-th power of unique natural numbers in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 29-Dec-2020 10:47:42

507 Views

In this tutorial, we are going to write a program that find the number of ways a integer can be expressed as sum of given n-th power of unique numbers.We have two integers number and power. And we need to find in how many ways can we represent the given ... Read More

Advertisements