- 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)
107 Views
In this article, we will be discussing a program to check if it is possible to finish all the given tasks on the basis of the given prerequisites.For example, let us say we have been given three tasks and prerequisites are [[1, 0], [2, 1], [3, 2]].( [1, 0] means that to pick up ‘1’ task; the ‘0’ task must be completed first.)Then, in this example since the ‘0’ task doesn’t have any prerequisite it can be completed first. Then the ‘1’ task can be completed, since the ‘0’ task has been completed. Similarly, both ‘2’ and ‘3’ tasks can ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
689 Views
In this article, we will be discussing a program to find ways an integer (say X) can be expressed as sum of n-th power of unique natural numbers.For example, let X = 100 and n = 2Then there would be 3 ways to express 100 as sum of squares of natural numbers.100 = 102 100 = 62 + 82 100 = 12 + 32 + 42 + 52 + 72This can be done easily by using recursion. We would start from 1 and go till the n-th root of the given number. In every run, we would subtract the n-th ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
81 Views
In this article, we will be discussing a program to find unique pairs of numbers having elements less than or equal to N and following some certain conditions −The square of difference between the two numbers must be equal to the LCM of those two numbers.The HCF of those two numbers can be represented as a product of any two consecutive numbers.The best approach to solve this problem would be to take two consecutive numbers (starting from 1) and finding the multiples of product of those numbers. Then among the multiples, to specify to one pair of numbers we need ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
1K+ Views
In this article, we will be discussing a program to find the union and intersection of two given unsorted arrays.Let us denote the two arrays with ‘A’ and ‘B’. Then union of those arrays is denoted by A ∪ B which is basically an array of all the elements in both the given arrays; provided that each element repeats only once.To find this, we will create a separate array and copy down all the elements from the first array. Then we will traverse through the elements of the second array and check if it is already present in the union ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
686 Views
In this article, we will be discussing a program to find out the uncommon characters during comparison of two different given strings.As we know, strings are nothing but an array of characters. Therefore, for comparison we would be traversing through the characters of one string and simultaneously checking if that element exists in the other string.If we let the first string be A and the second string B.Then it would give us A - B. Similarly we can calculate B - A.Combining both of these results we would get( A - B ) ∪ ( B - A )i.e the ... Read More
![Ayush Gupta](https://www.tutorialspoint.com/assets/profiles/134135/profile/60_13095-1568350695.jpg)
472 Views
In this tutorial, we will be discussing a program to find two numbers (say ‘a’ and ‘b’) such that botha+b = N and a*b = N are satisfied.Eliminating ‘a’ from both the equations, we get a quadratic equation in ‘b’ and ‘N’ i.eb2 - bN + N = 0This equation will have two roots which will give us the value of both ‘a’ and ‘b’. Using the determinant method to find the roots, we get the value of ‘a’ and ‘b’ as, $a= (N-\sqrt{N*N-4N)}/2\ b= (N+\sqrt{N*N-4N)}/2 $Example Live Demo#include //header file for the square root function #include using namespace ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
106 Views
We have a number N and a base b. In this program we have to check whether the number is starting with 1 in base b or not. Suppose a number 6 is given. In binary this is 110, so it starts with 1, in base 4 also it will be 124. Here also it starts with 1.As we know, if a number N is represented in base b, b gets converted to m+1 bit sequence bm bm-1 … b0. This implies bm bm + bm-1 * bm-1 + … + b0*b0 = N. The largest number will be 2*bm ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
255 Views
Here we will see another program to check whether a number is Quartan Prime or not. Before dive into the logic, let us see what are the Quartan Prime numbers? The Quartan primes are prime numbers, that can be represented as x4 + y4. The x, y > 0.To detect a number is like that, we have to check whether the number is prime or not, if it is prime, then we will divide the number by 16, and if the remainder is 1, then that is Quartan prime number. Some Quartan prime numbers are {2, 17, 97, …}Example Live Demo#include ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
246 Views
Here we will see, how to check, whether a number is full prime or not. A number is said to be a full prime, if it is prime, and all of its digits are also prime. Suppose a number is 37, this is full prime. But 97 is not full prime as 9 is not a prime number.One efficient approach is that; first we have to check whether any digit is present that is not prime. Digits must be in 0 to 9. In that range 2, 3, 5 and 7 are prime, others are not prime. If all are ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
770 Views
Here we will see another program to check whether a number is Pythagorean Prime or not. Before dive into the logic, let us see what are the Pythagorean Prime numbers? The Pythagorean primes are prime numbers, that can be represented as 4n + 1.To detect a number is like that, we have to check whether the number is prime or not, if it is prime, then we will divide the number by 4, and if the remainder is 1, then that is Pythagorean prime number. Some Pythagorean prime numbers are {5, 13, 17, 29, 37, 41, 53, …}Example Live Demo#include ... Read More