Server Side Programming Articles - Page 1959 of 2646

Print characters having odd frequencies in order of occurrence in C++

sudhir sharma
Updated on 03-Jan-2020 08:07:43

461 Views

In this problem, we are given string str by the user. And we have to print only those characters whose frequencies of occurrence in an odd number.To solve this problem, we have to find the total frequency of occurrence of a character in a string. And print only those characters of the string that have odd frequencies of occurrence.Let’s take an example to understand the topic better −Input : adatesaas. Output : dteExplanation −The characters with their frequency of occurrence are −a4d1t1e1s2Characters with odd frequency are d, t, e.AlgorithmNow let's try to create an algorithm to solve this problem −Step ... Read More

Print colored message with different fonts and sizes in C

sudhir sharma
Updated on 03-Jan-2020 08:05:02

3K+ Views

C/C++ programming language, the user is provided with functionality to customize the output based on the requirement of the user. C/C++ graphics functions are included in graphics.h header file. Using this library you can create different objects, set the color of text, change the font and size of the text and change the background of the output.Now, let's see the working of all the function to alter the text of the output in c/c++ programming language −setcolor() − This function is used to change the color of the output text.Syntaxsetcolor(int)Example#include #include int main(){    int gdriver = DETECT, gmode, i; ... Read More

Print common characters of two Strings in alphabetical order in C++

sudhir sharma
Updated on 03-Jan-2020 08:02:35

776 Views

In this programming problem, we are given two strings. And we have to find all the characters of the string that are common in both the string and we have to print these common characters in alphabetical order. And print ‘NO COMMON CHARACTERS ’ found if no common letters arise. Given that the string does not contain all lower case alphabets.Let’s take an example −Input : string1 : adsfhslf    string2 : fsrakf Output : affsExplanation − Between the two strings there are a, f, s. Hence the lexicographical output is ‘afs’.Input : string1 : abcde    string2 : glhyte ... Read More

Print Common Nodes in Two Binary Search Trees in C++

Farhan Muhamed
Updated on 18-Aug-2025 11:30:36

310 Views

A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will solve the problem of finding common nodes in two binary search trees (BSTs). Find Common Nodes in BSTs In this problem, you are given two binary search trees (BSTs) and your task is to develop a program that finds all the common nodes between these two trees. In the other words, the intersection ... Read More

Print common nodes on path from root (or common ancestors) in C++

sudhir sharma
Updated on 03-Jan-2020 07:56:25

195 Views

In this problem, we are given a binary tree and two nodes of the binary tree are defined. And we have to print all the common ancestors of the node i.e. common nodes that occur in the path from traversal from root to the node.Binary Tree is a special tree whose every node has at max two child nodes. So, every node is either a leaf node or has one or two child nodes.Example, Ancestor node is a node that is connected to lower-level nodes in a tree.The common ancestor node of two nodes is a node that is an ... Read More

Print Concatenation of Zig-Zag String in n Rows in C++

sudhir sharma
Updated on 03-Jan-2020 07:53:34

427 Views

In this problem, we are given a string that is a sequence of characters. And we are given the length of the zig-zag pattern and we have to print the concatenation string of this zig-zag string in n rows.Let’s see a few examples to understand the concept better, EXAMPLEInput : string = ‘STUVWXYZ’ n = 2. Output : SUWYTVXZExplanation − the zig-zag pattern for the string for a 2-row pattern is −S    U    W    Y    T    V    X    ZThe concatenation of this zig-zag pattern is - SUWYTVXZ.ExampleInput : string = ABCDEFGH n = ... Read More

Print concentric rectangular pattern in a 2d matrix in C++

sudhir sharma
Updated on 03-Jan-2020 07:50:37

941 Views

In this problem, we have to print a rectangular pattern in a 2D matrix in such a way that they are concentric to each other.Let’s take an example to understand this problem better, For n=4 is :    4 4 4 4 4 4 4    4 3 3 3 3 3 4    4 3 2 2 2 3 4    4 3 2 1 2 3 4    4 3 2 2 2 3 4    4 3 3 3 3 3 4    4 4 4 4 4 4 4Here, we have to print the pattern as ... Read More

Print consecutive characters together in a line in C++

sudhir sharma
Updated on 03-Jan-2020 07:47:02

334 Views

In this problem, we are given a string of characters and we have to print the same string in such a way that if two or more characters are consecutive then print them together in a single line otherwise print them in different lines i.e. with a line break.Let’s take an example to understand the concept better, Input : abcxstk Output : abc x st kExplanation − Since abc are in a sequence they are printed in a line. Then comes x which is not in sequence, so we add a linebreak here. Next is s which is not a ... Read More

Print cousins of a given node in Binary Treein C++

sudhir sharma
Updated on 03-Jan-2020 07:42:50

274 Views

Binary Tree is a special tree whose every node has at max two child nodes. So, every node is either a leaf node or has one or two child nodes.Example, In this problem, we are given a binary tree and we have a node of the tree and we have to find the cousin nodes of the node. No sibling nodes are to be printed for the binary tree.Let’s take an example, For the above binary tree, the cousin node is 5.To make the concept more clear let’s describe cousin node. In a binary tree, two nodes are said to ... Read More

Print digit’s position to be removed to make a number divisible by 6 in C++

sudhir sharma
Updated on 03-Jan-2020 07:32:06

286 Views

In this problem, we are given number and we have to remove more digit from the number. So that the new number formed after removal is divisible by 6.Let’s take an example to learn the concept better −Input : 1324 Output : 4Explanation − on removing the 4th number we will get 132 which is divisible by 6.Here, we are given a number and we have to return the position from where the number is removed to make it divisible by 6.For solving this problem, we will try to create a logic that solves the problem. For this, we will ... Read More

Advertisements