Server Side Programming Articles - Page 1781 of 2650

Program to find N-th term of series 2, 4, 3, 4, 15… in C++

Ayush Gupta
Updated on 03-Oct-2020 09:38:27

218 Views

In this problem, we are given a number N. Our task is to create a program to find N-th term of series 2, 4, 3, 4, 15… in C++.Problem Description − To find the sum of the given series, 2, 4, 3, 4, 15, 0, 14, 16 .... N termsWe will find the formula for the general term of the series.Let’s take an example to understand the problem, Input − N = 9Output − 9Solution Approach:The increase of the values in the series is linear i.e. no square values are in the series. Also, it’s value depends on other factors ... Read More

Program to find N-th term of series 1 4 15 24 45 60 92... in C++

Ayush Gupta
Updated on 03-Oct-2020 09:39:18

136 Views

In this problem, we are given a number N. Our task is to create a program to find N-th term of series 1 4 15 24 45 60 92... in C++.Problem description − To find the nth term of the series −1, 4, 15, 24, 45, 60, 92, 112 … N termsWe will find the general formula for the series.Let’s take an example to understand the problem, Input − N = 6Output − 60Solution Approach, The general term of the series is based on whether the value of N is even or odd. This type of series is a bit ... Read More

Count number of bits changed after adding 1 to given N in C++

Sunidhi Bansal
Updated on 15-May-2020 12:52:46

217 Views

We are given a number let’s say num and the task is to calculate the total number of bits changed when 1 is added to a number.Binary representation of a number is done by converting the given number into the form of 0’s and 1’s and it is done by various methods. In one method, we calculate the LCM of a given number by 2 and if a reminder is other than 0 then the bit is set to 1 else it will be set to 0.Addition table for bits are0 + 1 = 1 1 + 0 = 1 ... Read More

Count number of binary strings of length N having only 0’s and 1’s in C++

Sunidhi Bansal
Updated on 15-May-2020 12:50:50

530 Views

We are given a number let’s say, num and the task is to calculate the count of binary strings that can be formed through the given number num containing only o’s and 1’s.Binary Number System is one the type of Number Representation techniques. It is most popular and used in digital systems. Binary system is used for representing binary quantities which can be represented by any device that has only two operating states or possible conditions. For example, a switch has only two states: open or close.In the Binary System, there are only two symbols or possible digit values, i.e., ... Read More

Count full nodes in a Binary tree (Iterative and Recursive) in C++

Sunidhi Bansal
Updated on 15-May-2020 12:48:59

1K+ Views

We are given a binary tree and the task is to calculate the count of full nodes available in a binary tree using iterative and recursive approach. Full nodes are those nodes who have both the children and no child is null. Note that in full nodes we consider nodes with exactly two children.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 ... Read More

Count half nodes in a Binary tree (Iterative and Recursive) in C++

Sunidhi Bansal
Updated on 15-May-2020 12:43:29

469 Views

We are given a binary tree and the task is to calculate the count of half nodes available in a binary tree using iterative and recursive approach. Half nodes are those nodes who have only one child and another child is null. Note that in half nodes we don't consider leaf nodes.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 ... Read More

Count elements in a vector that match a target value or condition in C++

Sunidhi Bansal
Updated on 15-May-2020 12:23:16

634 Views

We are given a vector and the task is to calculate the count of those elements in a vector that matches a target value or condition.Vectors are sequence containers that can change size. Container is an object that holds data of the same type. Sequence containers store elements strictly in linear sequence.Vector stores elements in contiguous memory locations and enables direct access to any element using subscript operator []. Unlike arrays, vectors can shrink or expand as needed at run time. The storage of the vector is handled automatically.To support shrink and expand functionality at runtime, vector containers may allocate ... Read More

Count consonants in a string (Iterative and recursive methods) in C++

Sunidhi Bansal
Updated on 15-May-2020 12:21:38

729 Views

We are given a string with let’s say str of any length and the task is to calculate the count of consonants in the given string using both iterative and recursive methods.Consonants are those alphabets that are not vowel i.e alphabets except a, i, e, o, u are considered as consonants. So in the program below we need to find the count of alphabets other than these in string.The Recursion and Iteration both repeatedly execute the set of instructions. Recursion is when a statement in a function calls itself repeatedly. The iteration is when a loop repeatedly executes until the ... Read More

Count common subsequence in two strings in C++

Sunidhi Bansal
Updated on 15-May-2020 12:19:02

621 Views

We are given two strings, let's say str1 and str2 containing characters and the task is to calculate the common subsequences in both the strings. In the below program we are using dynamic programming and for that we need to know what dynamic programming is and at what problems it can be used.Dynamic programming approach is similar to divide and conquer in breaking down the problem into smaller and yet smaller possible sub-problems. But unlike, divide and conquer, these subproblems are not solved independently. Rather, results of these smaller subproblems are remembered and used for similar or overlapping sub-problems.Dynamic programming ... Read More

Count changes in Led Lights to display digits one by one in C++

Sunidhi Bansal
Updated on 15-May-2020 12:16:03

328 Views

We are given a positive number let’s say num and the task is to calculate the count of changes in the Led lights displayed one by one. We will assume that initially all LEDs are off and they will be started based upon the string value.For solving this question we need to understand what a seven segment display is and its working.What are Seven Segment DisplaysSeven segment displays are the output display device that provide a way to display information in the form of image or text or decimal numbers which is an alternative to the more complex dot matrix ... Read More

Advertisements