- 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++
69 Views
Here we will see one interesting problem related to modular equations. Suppose we have two values A and B. We have to find number of possible value that the variable X can take, such that (A mod X) = B holds.Suppose A is 26, and B is 2. So the preferred value for X will be {3, 4, 6, 8, 12, 24} So the count will be 6. That is the answer. Let us see the algorithm to get better idea.AlgorithmpossibleWayCount(a, b) −begin if a = b, then there are infinite solutions if a < b, then there ... Read More
289 Views
Here we will see some basic differences between C++, Java and the Python. At first we will see the C++ and Java differences, then the Java and Python differences.TopicC++JavaMemory ManagementIt uses pointers, structures, unions and referencesIt does not support pointers. It supports references. It also supports Threads, interfacesLibrariesLow level functional librariesWide range of library, with various functionalitiesMultiple InheritanceSupports multiple inheritance using normal classesSupports multiple inheritance with only interfaces (pure abstract classes)Operating OverloadingOperator overloading is supportedDoes not support operator overloadingProgram HandlingFunctions and variables can reside outside of the classesFunctions, variables can only be there inside classes or packagesPortabilityCode is dependent on ... Read More
709 Views
Here we will see what is the mutable keyword in C++. The mutable is one of the storage class in C++. Mutable data members are that kind of member, which can be changed always. Even if the object is const type. When we need only one member as variable and other as constant, then we can make them mutable. Let us see one example to get the idea.Example#include using namespace std; class MyClass{ int x; mutable int y; public: MyClass(int x=0, int y=0){ this->x = x; this->y = y; ... Read More
1K+ Views
The program takes a string and removes the spaces in it. This is useful when we want to save the space of our The following sample shows how it is done with an explanation.Input: Hello World Output: HelloWorldExplanationTo remove or delete spaces from the string or sentence, you have to ask the user to enter a string. Now start checking for spaces. If space will be found, then start placing the next character from the space to the back until the last character and continue to check for the next space to remove all the spaces present in the stringExample#include ... Read More
9K+ Views
In linear search algorithm, we compare targeted element with each element of the array. If the element is found then its position is displayed.The worst case time complexity for linear search is O(n).Input: arr[] = { 12, 35, 69, 74, 165, 54} Sea=165 Output: 165 is present at location 5.Explanationlinear search (Searching algorithm) which is used to find whether a given number is present in an array and if it is present then at what location it occurs. It is also known as sequential search. It is straightforward and works as follows: We keep on comparing each element with the ... Read More
2K+ Views
Check if a given number is a power of 2. First check below which numbers are the power of two or not. This code checks whether the number is odd and then divide it concurrently until it becomes 0 or odd. If it becomes 0 then it is a power 2 else it is not.A better choice is to take the log of the number. If it is an integer, then n is a power of 2 else not. Numbers that are powers of 2:2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 ... 22 = 4 25 ... Read More
307 Views
Positive integers 1, 2, 3, 4... are known as natural numbers.This program takes a positive integer from the user ( suppose user-entered n ) then, this program displays the value of 13+23+33+....+n3.Input: n = 3 Output: 36Explanation13+23+33 = 1 +8+27 = 36This program takes a positive integer from user( suppose user entered n ) then, this program displays the value of 13+23+33+....+n3.Example#include using namespace std; int main() { int n = 3; int sum = 0; for (int x=1; x
360 Views
Cycle sort is an in-place, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of writes to the original array, unlike any other in-place sorting algorithm. It is based on the idea that the permutation to be sorted can be factored into cycles, which can individually be rotated to give a sorted result.Unlike nearly every other sort, items are never written elsewhere in the array simply to push them out of the way of the action. Each value is either written zero times, if it's already in its correct position or written one ... Read More
285 Views
There is a string given, rearrange characters in the string such that the vowels and consonants occupy the alternate position. If string can’t be rearranged in the above manner, print “not possible”.The order of vowels with respect to each other and the order of consonants with respect to each other should be maintained.Input: abce Output: abecExplanationFind the number of vowels and consonants in the string.If the difference between no. of vowels and consonants are more than one, return “Not Possible”.If there is a condition that more vowels are present in the string than consonants, print the first vowel first and ... Read More
314 Views
A C++ program to find a number which occurs odd number of times in a given array of positive integers. In this array, all numbers occur even number of times.Input: arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7} Output: 7ExplanationUse two loops in which the outer loop traversed all elements one by one and inner loop counts the number of occurrences of the element traversed by the outer loop.Example#include using namespace std; int Odd(int arr[], int n){ for (int i = 0; i < n; i++) { int ctr = 0; ... Read More