
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

1K+ Views
In this tutorial, we are going to learn how to find the first non-repeating character in the given string. Let's see an example.Input −tutorialspointOutput −uLet's see the steps to solve the problem.Initialize the string.Initialize a map char and array to store the frequency of the characters in the string.Iterate over the string.Find the frequency of each character and store them in the map.Store the index of the character as well.Iterate over the character frequencies in the map.Print the first character with the frequency 1.ExampleLet's see the code.#include #include using namespace std; void findDistinctCharacters(string random_string) { // initializing ... Read More

102 Views
In this tutorial, we have to find whether the natural numbers from 1 to n is divided into two halves or not. It has to satisfy the following conditions.The absolute difference between the two series sum should be m.And the GCD of two sums should be 1 i.e.., co-primes.The sum of first n natural numbers is (n*(n+1))/2. We can find the sumOne and sumTwo as we have total sum and difference m. See the below equations.sumOne + sumTwo = (n*(n+1))/2 sumOne - sumTwo = mExampleCheck whether the absolute sum is equal to m or not. And then check for GCD. Live ... Read More

169 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 using namespace std; int productOfArrayDigits(int arr[], int n) { int product = 1; for (int i = 0; i < n; i++) { product *= arr[i]; } return product; } int firstDigitOfNumber(int n) { while (n >= 10) { n /= 10; } return n; } int main() { int arr[] = { 1, 2, 3, 4, 5, 6 }; cout

151 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 code. Live Demo#include using namespace std; void findFirstDigitOfFactorial(int n) { long long int fact = 1; for (int i = 2; i = 10) { fact = fact / 10; } cout

175 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 − z-(y^2+1)4xExampleLet's see the code. Live Demo#include using namespace std; void findParabolaProperties(float x, float y, float z) { cout

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); b = b ^ (b >> 4); b = b ^ (b >> 8); b = b ^ (b >> 16);If the last bit of the result is 1 then it's an odd parity else even parity.ExampleLet's see the code. Live Demo#include using namespace std; void findParity(int n) { ... Read More

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 the number to the sum using modulo operatorPrint the sumExampleLet's see the code. Live Demo#include using namespace std; void findTheSingleDigit(int n) { int sum = 0; while(n > 0 || sum > 9) { if(n == 0) { n = sum; sum = 0; } sum += n % 10; n /= 10; } cout

379 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 - y = d.Then the x = y + d.Let's say we have a number k such that x%k = y%k. Apply modulo k for the above equation and find the value d.x%k = (y+d)%k y%k = y%k +d%k d%k = 0From the above calculation, if the number k is ... Read More

101 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 ∆X to one side.You will get the value of ∆X as (b*c-a*d)/(d-c).We are given a, b, c, and d values. Finding \Delta XΔX value is straightforward.ExampleLet's see the code. Live Demo#include using namespace std; int findTheXValue(int a, int b, int c, int d) { return (b * c - ... Read More

124 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 zeroes to be flipped.Initialize window starting, ending indexes along with the length.Store the max sub array of consecutive 1's length and starting index.Iterate over the array until ending indexes crosses the array length.If the zeroes count is less than the max zeroes count then increment the ending index and zeroes ... Read More