C++ Articles

Page 47 of 597

Program to count number of configurations are there to fill area with dominos and trominos in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 159 Views

Suppose we have two shapes, Domino and Tromino. Dominos are 2 x 1 shape and Trominos are ‘L’ like shape. They can be rotated like below −If we have a number n, we have to find number of configurations to fill a 2 x n board with these two types of pieces. As we know in tiling, every square must be covered by a tile.So if the input is 3, then the output will be 5. So the arrangements can be [XYZ XXZ XYY XXY XYY] and [XYZ YYZ XZZ XYY XXY], here different letters are used for different tiles.To ...

Read More

Program to find number of unique subsequences same as target in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 216 Views

Suppose we have two lowercase strings s and t, we have to find the number of subsequences of s that are equal to t. If the answer is very large then return result by 10^9 + 7.So, if the input is like s = "abbd" t = "bd", then the output will be 2, as there are two possible subsequences "bd".s[1] concatenate s[3]s[2] concatenate s[3].To solve this, we will follow these steps −m := 10^9 + 7if size of t is same as 0, then −return 0if t is same as s, then −return 1if size of t > size ...

Read More

Program to count number of unique subsequences of a string in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 721 Views

Suppose we have a string s, we have to find the number of non-empty unique subsequences of s. If the answer is very large then mod the result by 10^9 + 7.So, if the input is like s = "xxy", then the output will be 5, as there are five subsequences: "x", "xx", "xy", "y" and "xxy".To solve this, we will follow these steps −m := 10^9 + 7n := size of sDefine an array table of size 26res := 0for initialize i := 1, when i

Read More

Finding sum of digits of a number until sum becomes single digit in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 9K+ Views

In this tutorial, we are going to write a program that sums digits of the given number until it becomes a single digit. Let's see an example.Input −4543Output −7Let's see the steps to solve the problem.Initialize a number.Initialize the sum to 0.Iterate until the sum is less than 9.Add each digit of the number to the sum using modulo operatorPrint the sumExampleLet's see the code.#include using namespace std; void findTheSingleDigit(int n) {    int sum = 0;    while(n > 0 || sum > 9) {       if(n == 0) {          n = sum;          sum = 0;       }       sum += n % 10;       n /= 10;    }    cout

Read More

First digit in factorial of a number in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 208 Views

In this tutorial, we are going to write a program the finds the first digit of a factorial. Let's see an example.Input − 7Output − 5Let's see the steps to solve the problem.Initialize the numberFind the factorial of the number.Divide the number until it becomes a single digit.ExampleLet's see the code.#include using namespace std; void findFirstDigitOfFactorial(int n) {    long long int fact = 1;    for (int i = 2; i = 10) {       fact = fact / 10;    }    cout

Read More

First N natural can be divided into two sets with given difference and co-prime sums in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 173 Views

In this tutorial, we have to find whether the natural numbers from 1 to n is divided into two halves or not. It has to satisfy the following conditions.The absolute difference between the two series sum should be m.And the GCD of two sums should be 1 i.e.., co-primes.The sum of first n natural numbers is (n*(n+1))/2. We can find the sumOne and sumTwo as we have total sum and difference m. See the below equations.sumOne + sumTwo = (n*(n+1))/2 sumOne - sumTwo = mExampleCheck whether the absolute sum is equal to m or not. And then check for GCD.#include ...

Read More

First triangular number whose number of divisors exceeds N in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 228 Views

In this tutorial, we are going to find a triangular number whose number of divisors are greater than n.If the sum of natural numbers at any point less than or equal to n is equal to the given number, then the given number is a triangular number.We have seen what triangular number is. Let's see the steps to solve the problem.Initialize the numberWrite a loop until we find the number that satisfies the given conditions.Check whether the number is triangular or not.Check whether the number has more than n divisors or not.If the above two conditions are satisfied then print ...

Read More

First uppercase letter in a string (Iterative and Recursive) in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 704 Views

In this tutorial, we are going to learn how find the first uppercase letter in the given string. Let's see an example.Input −TutorialspointOutput −TLet's see the steps to solve the problem using iterative method.Initialize the string.Iterate over the string.Check whether the current character is uppercase or not using isupper method.If the character is uppercase than return the current character.ExampleLet's see the code.#include using namespace std; char firstUpperCaseChar(string str) {    for (int i = 0; i < str.length(); i++)       if (isupper(str[i])) {          return str[i];       }       return ...

Read More

Fixed (or static) Partitioning in Operating System in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we are going to learn about the fixed partitioning in the operating system.Fixed partitioning is one to manage the memory in operating system. It's an old technique. It divides the memory into equal blocks. The size of each block is predefined and can not be changed.The memory is used for the contiguous processes.ExampleLet's see the sample program that allocates memory based on the process size.#include using namespace std; int main() {    int blockNumber = 5, processesNumber = 3;    int blockSize[5] = {4, 4, 4, 4, 4}, processSize[3] = {1, 2, 3};    int flags[5], allocation[5]; ...

Read More

Delete a Node from linked list without head pointer in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 2K+ Views

In this tutorial, we are going to learn how to delete a node without head pointer in a singly linked list.Let's see the steps to solve the problem.Write struct with data, and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Take a node from the linked list using the next pointer.Move the delete node to the next node.ExampleLet's see the code.#include using namespace std; struct Node {    int data;    struct Node* next; }; void deleteNodeWithoutHead(struct Node* deletingNode) {    if (deletingNode == NULL) {     ...

Read More
Showing 461–470 of 5,962 articles
« Prev 1 45 46 47 48 49 597 Next »
Advertisements