Programming Articles - Page 1956 of 3366

Count and Print the alphabets having ASCII value in the range [l, r] in C++

Sunidhi Bansal
Updated on 15-May-2020 10:31:23

336 Views

We are given with a string of any length and the task is to calculate the count and print the alphabets in a string having ASCII value in the range [l, r]ASCII value for character A-Z are given belowABCDEFGHIJKLMNOPQRS65666768697071727374757677787980818283TUVWXYZ84858687888990ASCII value for characters a-z are given below −abcdefghijklmnopqrs979899100101102103104105106107108109110111112113114115tuvwxyz116117118119120121122For ExampleInput − String str = “point       First = 111, Last = 117 Output − characters in the given range are: p, o , t       Count is: 3Explanation − since p, o and t lies in the range of [111, 117] these characters will be counted.Input − String ... Read More

Count Non-Leaf nodes in a Binary Tree in C++

Sunidhi Bansal
Updated on 15-May-2020 10:28:05

2K+ Views

We are given with a binary tree and the task is to calculate the count of non-leaf nodes available in a binary tree.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is as quick as in a sorted array and insertion or deletion operation are as fast as in linked list. Non-leaf nodes are also known as parent nodes as they have more ... Read More

Count nodes in Circular linked list in C++

Sunidhi Bansal
Updated on 15-May-2020 10:24:30

1K+ Views

We are given a circular linked list with the nodes and the task is to calculate the count of nodes present in a circular linked list.Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.In the below program, we are implementing a singly linked list as a circular linked list to calculate the count of nodes in that.For ExampleInput − nodes-: 20, 1, 2, 3, 4, ... Read More

Count all triplets whose sum is equal to a perfect cube in C++

Sunidhi Bansal
Updated on 15-May-2020 09:40:12

248 Views

We are given with an array of n integers and the task is to calculate the count all the triplets whose sum is equal to perfect cubeWhat is the perfect cubeA perfect cube is a number which is a cube of any number, like 125 is a cube of 5 so we can say that 125 is a perfect cube. Some of the perfect cube integers are 1, 8, 27, 64, 125….So, according to the problem in the array we have to find and count those triplets (set of 3 values) whose sum is equal to a perfect cube number. ... Read More

Count characters with same neighbors in C++

Sunidhi Bansal
Updated on 15-May-2020 09:27:28

267 Views

We are given a string with, let’s say, str and the task is to compute the count of characters in a string str having the same neighbors and that will include both left and right side of a character in a string. Also, in this scenario the first and last character in a string will always be considered as they have only one adjacent character.For ExampleInput − string str = “poiot” Output − count is 3Explanation − In the given string characters p, t and i are having the same neighbors so the count will be increased to 3.Input − ... Read More

Count Hexadecimal Number in C++

Sunidhi Bansal
Updated on 15-May-2020 09:26:02

434 Views

We are given a range having start and end and the task is to calculate the count of hexadecimal numbers or alphabets present in the given range.What are Hexadecimal Alphabets?In computer terms, hexadecimal numbers are those numbers that are having base 16 which means the binary digit can be represented in 16-bit. It consists of integer numbers starting from 0-15. Where 10 is represented as A, 11 as B, 12 as C, 13 as D, 14 as E and 15 as F.So, in the below program our task is to find whether the range consists of hexadecimal alphabets or not.For ... Read More

Count characters in a string whose ASCII values are prime in C++

Sunidhi Bansal
Updated on 15-May-2020 09:22:33

333 Views

We are given a string of any length containing both uppercase and lowercase letters and the task is to compute the count of those characters whose ASCII values are prime.The ASCII values of uppercase letters[A-Z] start with 65 till 90 and lowercase letters[a-z] starts with 97 till 122.For ExampleInput string str = ‘Aebg’ Output count is: 2Explanation − The ASCII value for A is 65 which is a non-prime number so it willn’t be counted, e is 101 which is a prime number so it will be counted, b is 66 which is a nonprime number so it willn’t be ... Read More

Count characters at same position as in English alphabets in C++

Sunidhi Bansal
Updated on 15-May-2020 09:20:23

263 Views

We are given a string of any length containing both uppercase and lowercase letters and the task is to compute the count of those characters that are at the same position as in english alphabets.For ExampleInput − String str = eBGD Output − Count is: 2Explanation − B and D are the characters that lie in the same order in english alphabets as B comes at second position and D comes at fourth position.Input − String str = Abcdeizxy Output − Count is: 5Explanation − A, B, C, D and E are the characters that lie in the same order ... Read More

Count and Sum of composite elements in an array in C++

Sunidhi Bansal
Updated on 15-May-2020 09:11:42

447 Views

We are given with an array of positive integers and the task is to calculate the count and sum of the composite elements in the given array.What are composite numbersFrom the given set of integers, the numbers that are not prime are called composite numbers except 1 which is neither composite nor prime instead it’s a unit number. So, it is clearly stated that a number can be either prime or composite except the number 1.The composite upto 100 are given below −4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, ... Read More

Count all the numbers less than 10^6 whose minimum prime factor is N C++

Sunidhi Bansal
Updated on 15-May-2020 09:08:22

222 Views

We are given a prime number let’s say, num and the task is to calculate the count of all the numbers less than 10^6 whose minimum prime factor is equal to num.For ExampleInput − num = 7 Output − Number of prime factors = 38095 Input − num = 3 Output − Number of prime factors = 16666Approach used in the below program is as followsInput the number let’s say numStart the loop, from i to 2 and i should be less than or equals to max value and increment the value of iInside the loop, check if s_prime[i] ... Read More

Advertisements