XOR of Prime Frequencies of Characters in a String in C++

sudhir sharma
Updated on 20-Apr-2020 11:41:56

207 Views

In this problem, we are given a string of characters, our task is to print the XOR of frequencies of characters of the string whose frequency of occurrence is a prime number.Let’s take an example to understand the problem, Input − TutorialsPointOutput −Here, we will check the frequency of occurrence of each character of the string and then find XOR of all the characters whose frequency is a prime number. For this will create an array of prime frequencies. Then we will store frequencies of characters of a string in a map and then matching with prime frequency array. If ... Read More

XOR of Sum of Every Possible Pair of an Array in C++

sudhir sharma
Updated on 20-Apr-2020 11:39:02

276 Views

In this problem, we are given an array of n elements. Our task is to generate a sequence of size n*n whose elements are the sum of a pair of all elements of A with itself. And print the xor elements of this sum array formed.Let’s take an example to understand the problem, Input − A (1, 4, 5)Output − 0Explanation −B (1+1, 1+4, 1+5, 4+1, 4+4, 4+5, 5+1, 5+4, 5+5) B(2, 5, 6, 5, 8, 9, 6, 9, 10) Xor of all values = 2^5^6^5^8^9^6^9^10 = 0.To solve this problem, we need to know some properties of Xor. The ... Read More

Get Nth Node in a Linked List in C++

sudhir sharma
Updated on 20-Apr-2020 11:27:28

716 Views

Here, we are given a linked list and an index. We have to write a function to get Nth node in a linked list.Let’s take an example to understand the problem, Inputlinked list = 34 -> 4 -> 9 -> 1 , n = 2Output9To go to the node specified by n. We will go node by node in the linked list and increase the index count until the required nth position is reached.Program to illustrate the program, Example Live Demo#include using namespace std; class Node{    public:    int data;    Node* next; }; void insertNode(Node** head_ref, int new_data) ... Read More

Program Producing Different Results in C and C++

sudhir sharma
Updated on 20-Apr-2020 11:24:53

179 Views

Write a program that compiler and runs both in c and c++ and produces different results.There are multiple types of programs that give different results when compiled in c and c++.i. Using character literals− c and c++ both treat characters differently. In C, they are treated as integer literals whereas, in C++, they are treated as characters.Example Live Demo#include int main(){    printf("%d", sizeof('a'));    return 0; }OutputC : 4 C++: 1ii. Use of binary number − binary values are not considered as binary in c, instead treat it as integer. But in c++, they are treated as binary.Example Live Demo#include int ... Read More

Calculate Power of X to N in C++

sudhir sharma
Updated on 20-Apr-2020 11:22:37

394 Views

In this problem, we are given two integers x and n. Our task is to write a program to calculate the pow(x,n). Let's take an example to understand the problem, Input: x = 5 , n = 3 Output: 125 Example Program to calculate the pow(x,n): #include using namespace std; float myPow(float x, int y) { if (y == 0) return 1; float temp = myPow(x, y / 2); if (y % 2 == 0) return temp * temp; else { if (y > 0) return x * temp * temp; else return (temp * temp) / x; } } int main() { float x = 5; int n = 7; cout

Calculate Size of a Tree Recursion in C++

sudhir sharma
Updated on 20-Apr-2020 11:19:20

2K+ Views

In this problem, we are given a tree and our task is to create a program to calculate the size of the tree using recursion.The size of a tree is the total number of nodes present in the tree.Let’s take an example to understand the problem, The size of the above tree is 5.To find the size of the tree, we will have to add the size of left subtree and right subtree and then increment it by 1. The recursive function will be called for both left and right subtrees of the tree. And if no subtree is found ... Read More

Find Maximum Depth or Height of a Tree in C++

sudhir sharma
Updated on 20-Apr-2020 11:18:04

812 Views

In this problem, we are given a binary tree. Our task is to write a program to find the maximum depth or height of the given tree.Let’s take an example to understand the problem, The height of the tree is 3.To find the maximum height of a tree, we will check the heights of its left and right subtree and add one to the maximum of both. This is a recursive process that will continue this the last node is of the tree is found and one is added progressively to find the height of the sub-trees.Above example solved using ... Read More

Reverse an Array or String in C++

sudhir sharma
Updated on 20-Apr-2020 11:15:49

1K+ Views

Here, we are given an array or a string of characters. We will create a program to reverse the elements of an array or string.Let’s take an example to understand the problem, Inputarray = {2, 5, 7, 1, 9}Output{9, 1, 7, 5, 2}Inputstring = “Hello!”Output!0lleHTo create a program, we will loop through the elements of the array/string(both work in the same way). Taking one variable for start and one of end. And swap both elements. Increment the start variable and decrement the end variable. The swapping will continue till start variable’s value is less than end variable.The program can be ... Read More

Create HTML5 Compliant Javadoc in Java 9

raja
Updated on 20-Apr-2020 10:20:55

273 Views

Before Java 9, we have to search in google to find out particular packages, class, interface, and method information. Since Java 9, Javadoc includes search options in the API documentation itself, and the output is HTML5 compliant.In the below example, we have created the "JavaDocTest.java" file in the "C:/JAVA" folder.Examplepublic class JavaDocTest {    /**       * Default method to be run to print       * Tutorialspoint       * @param args command-line arguments    */    public static void main(String args[]) {       System.out.println("Tutorialspoint");    } }The documentation generated by Java 9 ... Read More

C# Program to Implement FizzBuzz

George John
Updated on 20-Apr-2020 08:06:26

4K+ Views

Implementation of FizzBuzz involves printing numbers from 1 to 100. If the numbers are multiples of 3 then Fizz is printed. If they are multiples of 5, then Buzz is printed and if they are multiples of both 3 and 5 then FizzBuzz is printed.A program that demonstrates the implementation of FizzBuzz is given as follows.Example Live Demousing System; namespace FizzBuzzDemo {    public class example {       static void Main(string[] args) {          for (int i = 1; i

Advertisements