- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7347 Articles for C++
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
61 Views
In this tutorial, we will be discussing a program to find time taken for signal to reach all positions in a stringFor this we will be provided with a string containing ‘x’ and ‘o’. A signal originates from ‘x’ and travels in both directions changing one ‘o’ value in one unit time. Our task is to calculate the complete time to convert whole string into ‘x’s.Example Live Demo#include using namespace std; //calculating the total required time int findMaximumDuration(string s, int n) { int right = 0, left = 0; int count = 0, maximumLength = INT_MIN; s ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
130 Views
In this tutorial, we will be discussing a program to find two numbers with sum and product both same as N.For this we will be provided with an integer value. Our task is to find two other integer values whose product and sum is equal to the given value.Example Live Demo#include using namespace std; //finding a and b such that //a*b=N and a+b=N void calculateTwoValues(double N) { double val = N * N - 4.0 * N; if (val < 0) { cout
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
57 Views
In this tutorial, we will be discussing a program to find triplet such that number of nodes connecting these triplets is maximum.For this we will be provided with a tree with N nodes. Our task is to find a triplet of nodes such that the nodes covered in the path joining them in maximum.Example Live Demo#include #define ll long long int #define MAX 100005 using namespace std; vector nearNode[MAX]; bool isTraversed[MAX]; //storing the required nodes int maxi = -1, N; int parent[MAX]; bool vis[MAX]; int startnode, endnode, midNode; //implementing DFS to search nodes void performDFS(int u, int count) { ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
89 Views
In this tutorial, we will be discussing a program to find trace of matrix formed by adding Row-major and Column-major order of same matrix.For this we will be provided with two arrays one in row-major and other in columnmajor. Our task is to find the trace of the matrix formed by the addition of the two given matrices.Example Live Demo#include using namespace std; //calculating the calculateMatrixTrace of the new matrix int calculateMatrixTrace(int row, int column) { int A[row][column], B[row][column], C[row][column]; int count = 1; for (int i = 0; i < row; i++) for ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
99 Views
In this tutorial, we will be discussing a program to find uncommon characters of the two strings.For this we will be provided with two strings. Our task is to print out the uncommon characters of both strings in sorted order.Example Live Demo#include using namespace std; const int LIMIT_CHAR = 26; //finding the uncommon characters void calculateUncommonCharacters(string str1, string str2) { int isthere[LIMIT_CHAR]; for (int i=0; i
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
105 Views
In this tutorial, we will be discussing a program to find two distinct prime numbers with given product.For this we will be provided with an integer value. Our task is to find the two prime integer values such that their product is equal to the given value.Example Live Demo#include using namespace std; //generating prime numbers less than N. void findingPrimeNumbers(int n, bool calcPrime[]) { calcPrime[0] = calcPrime[1] = false; for (int i = 2; i
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
84 Views
In this problem, we are given two numbers, from which one is represented using array of digits. Our task is to create a program that will find the sum of two numbers where one number is represented as array of digits.Let’s take an example to understand the problem, Input: n = 213, m[] = {1, 5, 8, } Output: 371 Explanation: 213 + 158 = 371To solve this problem, we will simply digit by digit from the number which element of the array. It lsb of the number is added to the (n-1)th element of the array. The carry will ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
4K+ Views
In this problem, we are given two string that defines two large numbers. Our task is to create a program to find the sum of two large numbers.Let’s take an example to understand the problem, Input: number1 = “341299123919” number2 = “52413424” Output: 341351537343To solve this problem, we will traverse both the string. And add digit by digit and propagate the carry. And store the result digit by digit to sum string.AlgorithmInitialize sum = 0, carry = 0. Step 1: loop from n to 0. Step 1.1: intSum = number1[i] + number2[i] Step 1.2: carry = intSum/10. Sum += intSum ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
228 Views
In the problem, we are ginen two number k and n of the series K^n + ( K^(n-1) * (K-1)^1 ) + ( K^(n-2) * (K-1)^2 ) + ... (K-1)^n. Our task is to create a program to find the sum of the series.Let’s take an example to understand the problem, Input: n = 3, k = 4 Output: 175 Explanation: Sum of the series is = 4^3 + ( (4^2)*(3^1) ) + ( (4^1)*(3^2) ) + ( (4^0)*(3^3) ) = 64 + 48 + 36 + 27 = 175A simple way to solve the problem, is using a for ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
541 Views
In this problem, we are given an array arr[] of n numbers. Our task is to create a program to find the sum of XOR of all subarrays of the array.Here, we need to find all sub-arrays of the given array, and then for each subarray, we will find the xor of element and add the XOR value to the sum variable.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: Explanation: XOR of all subarrays for the array : XOR {5} = 5 XOR {1} = 1 XOR {4} = 4 XOR {5, 1} ... Read More