Data Structure
 Networking
 RDBMS
 Operating System
 Java
 MS Excel
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP
- Selected Reading
 - UPSC IAS Exams Notes
 - Developer's Best Practices
 - Questions and Answers
 - Effective Resume Writing
 - HR Interview Questions
 - Computer Glossary
 - Who is Who
 
Server Side Programming Articles - Page 2005 of 2650
 
			
			263 Views
Suppose we have two numbers n and fact. We have to find the largest power of n, that divides fact! (factorial of fact). So if fact = 5, and n = 2, then output will be 3. So 5! = 120, and this is divisible by 2^3 = 8.Here we will use the Legendre’s formula. This finds largest power of a prime, that divides fact!. We will find all prime factors of n, then find largest power of it, that divides fact!.So if fact is 146, and n = 15, then prime factors of n are 5 and 3. Sofor ... Read More
 
			
			2K+ Views
As we know some basic features of an object oriented programming language are the Inheritance, Encapsulation, Polymorphism. Any language that supports these features completely are known as object oriented programming languages. Some languages like C++ supports these three but not fully, so they are partially object oriented language. Let us see the reason why C++ is not known as completely object oriented language.In C++, we need the main() function to start executing, but in C++, the main functions are not present inside the class. So we can also write code without using class in C++. Some OOP languages like JAVA, ... Read More
 
			
			536 Views
Suppose we have a number of n digits. We have to find the maximum number that can be obtained using all digits of digits of that number. So if the number is say 339625, then maximum number can be 965332.From the problem, we can see that we can easily sort the digits in non-increasing order, then print them. But we can solve this using more efficient way. We can create one array of size 10 to store the frequency of each digit, then print the numbers from 9 to 0 accordingly.Example Live Demo#include #include using namespace std; int maxNumFromNum(int ... Read More
 
			
			241 Views
Here we will see when we need to create own assignment operator in C++. If a class do not have any pointers, then we do not need to create assignment operator and copy constructor. C++ compiler creates copy constructor and assignment operator for each class. If the operators are not sufficient, then we have to create our own assignment operator.Example#include using namespace std; class MyClass { //no user defined assignment operator or copy constructor is present int *ptr; public: MyClass (int x = 0) { ptr = new int(x); } void setValue (int x) { *ptr = x; } void print() { cout
 
			
			362 Views
Suppose we have an array of n elements. We have to find the maximum number of elements to select from the array, such that the absolute difference between any two of the chosen elements is less than or equal to 1. So if the array is like [2, 2, 3, 4, 5], then the element will be 3, so the sequence with maximum count is 2, 2, 3.The absolute difference of 0 and 1 means, that the number can be of type x and x + 1. So the idea is to store the frequencies of array elements. So if ... Read More
 
			
			708 Views
Here we will see how to use the sort() function of C++ STL to sort an array So if the array is like A = [52, 14, 85, 63, 99, 54, 21], then the output will be [14 21 52 54 63 85 99]. To sort we will use the sort() function, that is present in the header file . The code is like below −Example Live Demo#include #include using namespace std; int main() { int arr[] = {52, 14, 85, 63, 99, 54, 21}; int n = sizeof(arr) / sizeof(arr[0]); cout
 
			
			617 Views
Suppose we want to make a stack that can store the maximum element in the stack. And we can get it in O(1) time. The constraint is that, it should use O(1) extra space.We can make one user-defined stack, that will store the max value, when one operation is performed, like pop or peek, then the max will be returned. For peek operation, return the maximum of stack top and the max element, for pop operation, when the top element is larger, then print it and update max as 2*max – top_element. otherwise return top_element. For push operation update the ... Read More
 
			
			1K+ Views
In this section we will see how to create and use complex numbers in C++. We can create complex number class in C++, that can hold the real and imaginary part of the complex number as member elements. There will be some member functions that are used to handle this class.In this example we are creating one complex type class, a function to display the complex number into correct format. Two additional methods to add and subtract two complex numbers etc.Example Live Demo#include using namespace std; class complex{ int real, img; public: complex(){ ... Read More
 
			
			407 Views
Here we will see some good tricks of C++ programming language that can help us in different area. Like if we want to participate in some competitive programming events, then these tricks will help us to reduce the time for writing codes. Let us see some of these examples one by one.Checking whether a number is odd or even without using % operator. This trick is simple. We can perform bitwise AND operation with the number and 1. If the result is non-zero then this is odd, otherwise this is even. The logic is too simple. All odd numbers have ... Read More
 
			
			180 Views
A matrix of different characters is given. Starting from one character we have to find longest path by traversing all characters which are greater than the current character. The characters are consecutive to each other.Starts from E.To find longest path, we will use the Depth First Search algorithm. During DFS, some sub problems may arise multiple times. To avoid the computation of that sub problems again and again, we will use dynamic programming approach.Example Live Demo#include #define ROW 3 #define COL 3 using namespace std; // tool matrices to recur for adjacent cells. int x[] = {0, 1, 1, -1, 1, ... Read More