- 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++
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
86 Views
STATEMENT − Balance pans using given weights that are powers of a number.DESCRIPTION − In this problem we are given a pan based weighing machine. we are given a weight T and some other weights whose values are powers of a number a. We need to balance the pans using the given weights.Now, based on this we have this equation, T + (some power of a) = (some other power of a)Now, we should remember that there is exactly one weight corresponding to a power value.Example, T = 12 : a = 4Using the below values, we can balance the ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
517 Views
Bakhshali approximation is a method of computing the square root of a number which is not a perfect square. Now, lets brush-related terms to easily understand the concept.Square root of a number x is a number that satisfies the following condition, y2 = x.Perfect Square is a number whose square roots are w. For example 16 is perfect square as its roots are 4 and 4.There are multiple methods defined mathematically to find the square root of a number. In this tutorial, we are going to learn about Bakhshali approximation to find the square root of a number.It is a ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
74 Views
We have to take a number Y, we will find smallest number X, such that X! contains at least Y number of training zeros. For example, if Y = 2, then the value of X = 10. As X! = 3228800. It has Y number of zeros.We can solve this using binary search. The number of trailing zeros in N! is given by the count of the factors 5 in N!. X can be found using binary search in range [0, 5*Y]Example #include using namespace std; int factorCount(int n, int X) { if (X < n) ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
2K+ Views
Suppose we have an array of n elements. We have to find the first, second smallest elements in the array. First smallest is the minimum of the array, second smallest is minimum but larger than the first smallest number.Scan through each element, then check the element, and relate the condition for first, and second smallest elements conditions to solve this problem.Example #include using namespace std; int getTwoSmallest(int arr[], int n) { int first = INT_MAX, sec = INT_MAX; for (int i = 0; i < n; i++) { if (arr[i] < first) { ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
100 Views
Consider we have few elements in a linked list. We have to find the multiplication result of last n number of elements. The value of n is also given. So if the list is like [5, 7, 3, 5, 6, 9], and n = 3, then result will be 5 * 6 * 9 = 270.The process is straight forward. We simply read the current element starting from left side, then add the elements into stack. After filling up the stack, remove n elements and multiply them with the prod. (initially prod is 1), when n number of elements are ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
67 Views
Consider we have few elements in a linked list. We have to find the multiplication result of first k number of elements. The value of k is also given. So if the list is like [5, 7, 3, 5, 6, 9], and k = 3, then result will be 5 * 7 * 3 = 105.The processes is straight forward. We simply read the current element starting from left side, then multiply it with the prod. (initially prod is 1), when k number of elements are traversed, then stop.Example#include #include using namespace std; class Node{ public: ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
116 Views
Suppose we have the diameter and the height of the cylinder, we have to find the perimeter of the cylinder. As the perimeter is the outline of two dimensional object, then we cannot find the perimeter of one three dimensional object directly. We can make a cross section of the cylinder, and convert it as rectangle, then find the perimeter. The two sides of the rectangular cross section are the diameter, and the height. So perimeter is −p=(2*d)+(2*h)Example#include using namespace std; int getCylinderPerimeter(int d, int h) { return (2*d) + (2*h); } int main() { int diameter = ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
56 Views
Suppose we have the center coordinate and one coordinate point on the perimeter of the circle. We have to find the another point on the perimeter. Consider the center points are (p, q), and one given point is (a, b). We have to find the point (x, y). As we know that the center is the middle point of the diameter. So we can write them like −(p, q)=(a+x/2, b+y/2)Or from this the (x, y) can be expressed as −x=2p-a, y=2q-bExample#include using namespace std; int getCylinderPerimeter(int d, int h) { return (2*d) + (2*h); } int main() { ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
92 Views
Consider we have a digit d, and the upper limit n. we have to find all numbers that contains d in range 0 to n. So if n = 20, and digit is 3, then the numbers will be [3, 13].To solve this problem, we will take every number as string, then if the digit is present in the string, the number will be printed, otherwise ignored.Example#include using namespace std; int getAllNumWithDigit(int n, int d) { string str = ""; str += to_string(d); char ch = str[0]; string p = ""; p += ch; for (int i = 0; i
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
422 Views
Suppose we have a number n. our task is to find next perfect square number of n. So if the number n = 1000, then the next perfect square number is 1024 = 322.To solve this, we have get the square root of the given number n, then take the floor of it, after that display the square of the (floor value + 1)Example#include #include using namespace std; int justGreaterPerfectSq(int n) { int sq_root = sqrt(n); return (sq_root + 1)*(sq_root + 1); } int main() { int n = 1000; cout