Found 7346 Articles for C++

Multiply the given number by 2 such that it is divisible by 10

Rinish Patidar
Updated on 14-Mar-2023 14:55:40

231 Views

This problem statement says that we are allowed to perform only one operation i.e. multiply the given number by 2 such that it is divisible by 10. We will be given a number say n. The only operation that we can perform on a given number is that we can multiply the given number by 2 until it is divisible by 10. We need to determine the minimum number of operations required to make the number such that it is divisible by 10 by repeatedly multiplying the given number n by 2. Else, print -1 if it is not possible ... Read More

Minimum steps in which N can be obtained using addition or subtraction at every step

Rinish Patidar
Updated on 14-Mar-2023 14:52:03

242 Views

From the above problem statement, our task is to get the minimum steps in which a given number N can be obtained using addition or subtraction at every step. We can understand that we need to print the minimum number of steps that we can perform and sequence of the steps on any given integer N to reach the number starting from 0 by addition or subtraction of the step number. In this problem set, we can add or subtract the number equal to the step count from the current location at each step. For instance, we can add either ... Read More

Level order traversal with direction change after every two levels(Implementation in C/C++)

Rinish Patidar
Updated on 20-Mar-2023 16:06:06

116 Views

Level Order TraversalThis is one of the algorithms that processes or prints all nodes of a binary tree by traversing through depth, starting at the root and moving on to its children and so forth.Example INPUT − OUTPUT − 2 4 7 3 6 11 This task involves printing a binary tree's level order traversal so that the first two levels are printed from right to left direction, and the next two levels from left to right direction, and so on. The challenge is that a binary tree's level order traverse must be ... Read More

Largest of two distinct numbers without using any conditional statements or operators

Rinish Patidar
Updated on 14-Mar-2023 14:33:44

1K+ Views

In this problem set, we will be given any two distinct positive numbers, let’s say a and b, we need to return the largest of two distinct numbers without using any conditional statements (if-else) or any operators(, ==, !=, etc.) in c++. The main difficulty of the problem includes that we need to determine the largest of any two distinct positive numbers without using any operators or conditional statements. For example, INPUT: x=12, y=20 OUTPUT: 20 INPUT: x=3, y=2 OUTPUT: 3 Below is the algorithm that we will be using to solve this problem. Algorithm We will use type casting ... Read More

Find the Smallest Positive Number Missing From an Unsorted Array

Rinish Patidar
Updated on 14-Mar-2023 14:31:04

2K+ Views

Our objective is to find the smallest positive number that is missing from an unsorted array. We will be given an array a[] of both positive and negative numbers, we need to get the smallest positive number that is missing from an unsorted array in this problem. We can modify the array given in this problem to solve it. For example, INPUT : a[] = {5, 8, -13, 0, 18, 1, 3} OUTPUT : 2 INPUT : a[] = {7, 10, -8, 1, 4} OUTPUT : 2 In the above examples, we are given an unsorted array as an input. ... Read More

Divide two integers without using multiplication, division and mod operator

Rinish Patidar
Updated on 14-Mar-2023 14:24:05

4K+ Views

In this problem, we simply need to divide two integers without using multiplication, division and mod operator. Though we can use addition or multiplication or bit manipulation. The problem statement states that we will be given two integers x and y. Without using multiplication, division or mod operator, we need to determine the quotient after dividing x by y. Example INPUT: x=15 , y=5 OUTPUT: 3 INPUT: x=10 , y=4 OUTPUT: 2 INPUT: x=-20 , y=3 OUTPUT: -6 Approach Approach-1(using simple mathematics) In this approach, we will use a simple mathematics algorithm. Below is the step-by-step illustration of the ... Read More

Centered Dodecagonal Number

Rinish Patidar
Updated on 14-Mar-2023 14:07:38

152 Views

A figurative number that depicts a dodecagon is called a dodecagonal number. The Centered Dodecagonal number is represented by a dot in the centre and other dots encircling it in the successive dodecagonal (i.e. a 12-sided polygon) layers. Centered Dodecagonal number can be better explained with the below figure. For n=1, only a single dot will be there in the centre. So the output will be 1. For n=2, a single dot in the centre followed by a dodecagon encircling it. Thus, the total number of dots will be 13. So the next centred dodecagonal number ... Read More

Case-specific sorting of strings

Mallika Gupta
Updated on 15-Mar-2023 10:21:25

276 Views

Strings are the storage elements for storing different kinds of letters and symbols. It is indicative of a stream of characters in C++. Strings are denoted in double quotes or single quotes. The given input string can be comprised of both uppercase and lowercase characters. The problem statement is to change the case of the characters of the string, in such a way that the letter which was originally written in lowercase is converted into uppercase and vice versa. Some of the examples illustrating the problem statement are as follows − Sample Examples Example 1 : "AbCd" Output : bAdC ... Read More

Perfect Power (1, 4, 8, 9, 16, 25, 27, …)

Eva Sharma
Updated on 10-Mar-2023 12:35:48

781 Views

A Perfect Power is a Natural Number that is the product of equal natural factors. It can also be defined as an integer that can be expressed as a square power or a higher power of another integer greater than one. For example, 4 can be expressed as the product of 2*2. 27 can be expressed as the product of 3*3*3. Hence, 4 and 27 are perfect powers. Problem Statement Given a number n, find the count of perfect numbers which are less than or equal to n. Example 1 Input = 14 Output = 3 Explanation 1 ... Read More

Legendre’s Conjecture: Concept, Algorithm, Implementation in C++

Eva Sharma
Updated on 10-Mar-2023 12:31:11

188 Views

The Legendre’s Conjecture states that at least one prime number always exists between two consecutive natural numbers' squares. Mathematically, there is always a prime number p between any two numbers n2 and (n+1)2. n is a natural number. A conjecture means a conclusion that doesn't has mathematical proof. Hence, Legendre's Conjecture is just a statement with no mathematical proof. Problem Statement For a number n, print the number of primes in the range of n2 to (n+1)2 from 1 to n. Examples Input: 4 Output: For i = 1: Total primes in the range 1 and 4 = 2 ... Read More

Advertisements