- 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++
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
70 Views
Given a number N. We have to find the count of such numbers that can be formed using digit 3 and 4. So if N = 6, then the numbers will be 3, 4, 33, 34, 43, 44.We can solve this problem if we look closely, for single digit number it has 2 numbers 3 and 4, for digit 2, it has 4 numbers 33, 34, 43, 44. So for m digit numbers, it will have 2m values.Example Live Demo#include #include using namespace std; long long countNumbers(int n) { return (long long)(pow(2, n + 1)) - 2; } int main() { int n = 3; cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
89 Views
Suppose we have a number n, we have to find the closest and smaller tidy number of n. So a number is called tidy number, if all of its digits are sorted in non-decreasing order. So if the number is 45000, then the nearest and smaller tidy number will be 44999.To solve this problem, we will traverse the number from end, when the tidy property is violated, then we reduce digit by 1, and make all subsequent digit as 9.Example Live Demo#include using namespace std; string tidyNum(string number) { for (int i = number.length()-2; i >= 0; i--) { ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
134 Views
Suppose we have two endpoints of diameter of a circle. These are (x1, y1) and (x2, y2), we have to find the center of the circle. So if two points are (-9, 3) and (5, -7), then the center is at location (-2, -2).We know that the mid points of two points are −$$(x_{m},y_{m})=\left(\frac{(x_{1}+x_{2})}{2},\frac{(y_{1}+y_{2})}{2}\right)$$Example Live Demo#include using namespace std; class point{ public: float x, y; point(float x, float y){ this->x = x; this->y = y; } void display(){ cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
112 Views
Suppose we have a positive number n, and we have to find the sum of N and its maximum prime factor. So when the number is 26, then maximum prime factor is 13, so sum will be 26 + 13 = 39.Approach is straight forward. Simply find the max prime factor, and calculate the sum and return.Example Live Demo#include #include using namespace std; int maxPrimeFact(int n){ int num = n; int maxPrime = -1; while (n % 2 == 0) { maxPrime = 2; n /= 2; } for (int i = 3; i 2) maxPrime = n; return maxPrime; } int getRes(int n) { int sum = maxPrimeFact(n) + n; return sum; } int main() { int n = 26; cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
1K+ Views
Suppose we have a positive number n, and precision p. We have to find square root of the number n up to p decimal places using binary search technique. So if the number is n = 50, and p = 3, then output is 7.071.So solve this, we have to follow some steps −Initialize start := 0 and end := nCompare the square of mid integer, if this is equal to the number then integral part has found out, otherwise look for left or right as required.Once we have completed the task for integral part, then do for the fractional ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
109 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
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
4K+ 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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
197 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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
81 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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
116 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