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
C++ Articles - Page 496 of 719
417 Views
In this tutorial, we will be discussing a program to print the last N lines.For this, we will be provided with a string that consists of the new line character to denote the start of the next line and the number of lines to be printed from the last. Our task is to start from the last and print all the N lines counting from the last.Example#include using namespace std; #define DELIM '' //printing the last N lines void print_last_lines(char *str, int n){ if (n
224 Views
In this tutorial, we will be discussing a program to print the last 10 lines.For this, we will be provided with a string that consists of the new line character to denote the start of the next line. Our task is to start from the last and print all the 10 lines counting from the last.Example#include using namespace std; #define DELIM '' //printing the last 10 lines void print_last_lines(char *str, int n){ if (n
968 Views
In this tutorial, we will be discussing a program to print the given Kite pattern.For this, we will be taking the input as N=5. Our task is to print the given Kite structure with the overall height of 2N+1 = 5. This includes 9 lines for the upper diamond structure and 2 for the lower incomplete diamond structure.Example Live Demo#include #include using namespace std; int main(){ int i, j, k, sp, space = 4; char prt = '$'; //printing the upper half of the first diamond for (i = 1; i = 1; sp--){ cout
410 Views
In this tutorial, we will be discussing a program to print given inverse diamond pattern.For this, we will be provided with the value of N. Our task is to print an inverse the diamond pattern according to the height of 2N-1.Example Live Demo#include using namespace std; //printing the inverse diamond pattern void printDiamond(int n){ cout
272 Views
In this tutorial, we will be discussing a program to print a given interesting pattern.For this, we will be provided with the half-width of the pattern. Our task is to print a similar pattern according to the given width with its left and right portions being mirror images of one another.Example Live Demo#include //printing the given pattern void print_pattern(int n){ int i,j; //printing the upper half for (i=1; i
293 Views
In this tutorial, we will be discussing a program to print a Hut pattern.For this, we will be provided with the width of the hut to be printed (say N). Our task is to print a hut structure of the given width using stars and a gate inside the hut using line characters.Example Live Demo#include using namespace std; //printing the given hut structure int print_hut(int n){ int i, j, t; if (n % 2 == 0) { n++; } for (i = 0; i = n / 5) || (j >= n / 5 && j < n - n / 5 && i == 0) || (j == 0 && i >= n / 5) || (j == t && i > n / 5) || (i
260 Views
Problem statementGiven an array of N elements and two integers A, B which belongs to the given array. Create a Binary Search Tree by inserting element from arr[0] to arr[n-1]. The task is to find the maximum element in the path from A to B.ExampleIf array is {24, 23, 15, 36, 19, 41, 25, 35} the we can form BST as follows −If we consider A = 19 and B = 41 then maximum element between these two nodes is 41AlgorithmFind Lowest Common Ancestor(LCA) of node A and B.Find maximum node between LCA and A. Let us call it as ... Read More
427 Views
Problem statementGiven an undirected tree which has even number of vertices, we need to remove the maximum number of edges from this tree such that each connected component of the resultant forest has an even number of vertices.ExampleIn above shown tree, we can remove at max 2 edges 0-2 and 0-4 shown in red such that each connected component will have even number of vertices.AlgorithmDo DFS from any starting node as tree is connectedInitialize count of nodes in subtree rooted under current node as 0Do following recursively for every subtree of current node −If size of current subtree is even, ... Read More
135 Views
Problem statementWe have given a positive number n, and we have to find a 3*3 matrix which can be formed with combination of 0 or n and has maximum determinants.ExampleIf n = 15 then we can create matrix as follows −{{15, 15, 0}{0, 15, 15}{15, 0, 0}}For any 3*3 matrix having elements either 0 or n, the maximum possible determinant is 2 *(n)3. Hence answer is −2 * (15)3 = 6750AlgorithmFor any 3*3 matrix having elements either 0 or n, the maximum possible determinant is 2 *(n)3ExampleLet us now see an example − Live Demo#include using namespace std; int getMaxDeterminant(int ... Read More
134 Views
Problem statementGiven a range [L, R], the task is to find a pair (X, Y) such that L ≤ X < Y ≤ R and X & Y is maximum among all the possible pairs then print the bitwise AND of the found pair.ExampleIf L = 1 and R = 10 then maximum bitwise AND value is 8 which can be formed as follows −1000 # Binary representation of 8 Bitwise AND 1001 # Binary representation of 9 ---- 1000 # Final resultAlgorithmIterate from L to R and check the bitwise AND for every possible pair and print the maximum ... Read More