Found 7197 Articles for C++

Replace every consonant sequence with its length in the given string

Tapas Kumar Ghosh
Updated on 20-Apr-2023 12:14:08

399 Views

This article will help us understand how to replace the consecutive consonant sequence with its length in the given string. Consonants are series of alphabetical letters that are not vowels. Here we need to first identify which letter in the string are consonants. For example, in the word “abcdiopqrsu”, the consonant sequence “bcd” and “pqrs”. Next, we would replace each consonant sequence with its length. So the word “bcd” would replace with “3” because there are three consecutive consonants, and the same with the word “pqrs” replace with “4” as there are four consecutive consonants. Algorithm First, we ... Read More

Pythagorean Quadruple

Vanshika Sood
Updated on 19-Apr-2023 11:13:12

697 Views

A group of four positive integers (a, b, c, and d) that satisfy the Pythagorean equation are called Pythagorean quadruples. The equation can be written as: a2 + b2 + c2 = d2 , with ‘d’ being the largest value out of the given numbers. In other words, the square of the fourth integer should be equal to the sum obtained by adding the squares of the previous three numbers. (1, 2, 2, 3) is a Pythagorean quadruplet as (12 + 22 + 22) = (1 + 4 + 4) = (9) = (32). Due to the requirement ... Read More

Palindromic Selfie Numbers

Vanshika Sood
Updated on 19-Apr-2023 11:08:35

316 Views

A number is considered to be a “Selfie Number” if it can be represented using only its own digits and certain mathematical operations. For example, 936 is a selfie number. $$\mathrm{936\:=\:(\sqrt{9})!^{3} \:+\:6!\:=\:216\:+\:720\:=\:936}$$ Here it can be observed that a series of operations are performed on the digits of the original number and the resultant is equal to the original number. Palindromic Selfie Numbers are a special kind of selfie number. They satisfy the selfie multiplicative rule. Consider a number x. Let the number formed by reversing the digits of x be $\mathrm{x^\prime}$. Let y be a ... Read More

Closest Numbers from a List of Unsorted Integers

Vanshika Sood
Updated on 19-Apr-2023 11:06:15

1K+ Views

In the following article, we discuss two approaches to find the closest numbers from a list of unsorted integers. Let us first understand what is meant by the term ‘closest numbers’. Closest numbers are the pair(s) of numbers which have the least difference between them. Problem Statement Given a list of distinct unsorted integers, we need to find the pair of elements that have the least difference between them. If there are multiple pairs, we need to find all of them. Furthermore, in the article wherever there is a mention of difference, it means absolute difference. Examples Input: [44, 42, ... Read More

Delete a Linked List Using Recursion

Vanshika Sood
Updated on 19-Apr-2023 11:04:06

1K+ Views

Linked List A linked list is a linear data structure in which the elements are stored at non-contiguous memory locations. Each element consists of a node. A node is composed of a data field, which holds the value of the element, and an address field, which points to the location of the next node in the series. The first node of the linked list is referred to as the ‘head’ of the list. The last element of the linked list can be defined as the element which points to NULL. A diagrammatic representation of a linked list is shown below. ... Read More

To Check if a Number is a Munchhausen Number

Vanshika Sood
Updated on 19-Apr-2023 11:02:04

801 Views

Munchhausen Numbers are peculiar numbers which possess a unique property. A number is considered to be munchhausen if the sum of the digits of the number, raised to their own power, is equal to the original number. These numbers are uncommon and not many of them are known. If the definition 00 = 0 is used, then 0 can also be considered a munchhausen number. The following article provides a method to determine whether a number is munchhausen or not while keeping in mind these characteristics of munchhausen numbers. Problem Statement The task at hand is to check whether a ... Read More

Position of n among the numbers made of 2, 3, 5 & 7

Rinish Patidar
Updated on 18-Apr-2023 15:36:38

298 Views

The problem statement includes printing the position of n among the numbers made of 2, 3, 5 and 7, where n will be any positive number given by the user. The numbers made of 2, 3, 5 and 7 means this will be the sequence of the strictly increasing numbers which comprises only digits 2, 3, 5 or 7 i.e. first four prime numbers. The first few numbers of the sequence where all numbers have only 2, 3, 5 and 7 as their digits are 2, 3, 5, 7, 22, 23, 25, 27, 32, 33, 35, 37, and so on. ... Read More

BMP 180 Pressure Sensor

Saba Hilal
Updated on 18-Apr-2023 10:48:17

517 Views

BMP180 sensor is a sensor that can be attached to a microcontroller on a breadboard and can measure the pressure, temperature, and altitude of a place. It can be connected to controllers such as ESP32 or Arduino and can be used by programs to read the values. In this article, using three different examples, the use of the BMP180 Sensor is demonstrated using ESP32. The circuit is made using an ESP32 microcontroller and BMP180 sensor and the programs to measure the temperature or pressure or altitude are written using Arduino software. Example 1 − Measuring the temperature of a place ... Read More

Sort an array containing two types of elements

Vaishnavi Tripathi
Updated on 11-Apr-2023 17:02:38

311 Views

There are different approaches to sort an array containing only two types of elements i.e., only 1’s and 0’s. We will discuss three different approaches to do so. First approach simply uses a predefined sort() function to sort the given array. Second approach is a count sort approach in which we will count the number of zeroes and ones and then update the array by first writing zero for the number of times 0 was counted and then writing 1’s for the number of times we counted one. In the last approach, we used the two pointer method. Problem statement ... Read More

Expressing factorial n as sum of consecutive numbers

Vaishnavi Tripathi
Updated on 11-Apr-2023 17:01:33

355 Views

We will discuss two approaches to find out how we can express the factorial of a number as the sum of consecutive numbers. First one is a straightforward and simple approach while in the other approach we use the concept of arithmetic progression to make it less complex in terms of time and space occupied. Problem statement We are given a number and we need to find out the number of ways in which we can represent the factorial of the number as a sum of consecutive natural numbers. This involves two different functions − To find the ... Read More

Advertisements