Programming Articles

Page 1442 of 2547

Program to print all palindromes in a given range in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 563 Views

In this tutorial, we will be discussing a program to print all palindromes in a given range.For this we will be given the mathematical range in which the palindromes are to be found. Our task is to find all the palindromes in that range and print it back.Example#include using namespace std; //checking if the number is a palindrome int is_palin(int n){    int rev = 0;    for (int i = n; i > 0; i /= 10)    rev = rev*10 + i%10;    return (n==rev); } void countPal(int min, int max){    for (int i = min; i

Read More

Long Pressed Name in C++

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

Suppose a man is typing some name on keyboard. Sometimes some buttons are long-pressed by mistake. So it may type one or more extra character. So we will take two strings, and check whether the second string is long-pressed name or not. So if the name is “Amit”, and second string is “Ammittt” is longpressed name. But “Ammttt” is not, because character i is not present here.To solve this, we will follow these steps −let j := 0for i := 0, i < second.size, increase i by 1 −if j < actual_name.size and actual_name[j] = second[i], thenincrease j by 1return ...

Read More

Print all combinations of points that can compose a given number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 284 Views

In this problem, we are given the total score n. Print all combinations of basketball points that are 1, 2, and 3 that give a total score of n.Let’s see an example to understand the problem, Input: 4 Output: 1 1 1 1 1 1 2 1 2 1 1 3 2 1 1 2 2 3 1To solve this problem, we will use recursion. And fix and resources for rest values n-s, where s is the score. If the combination adds up to n, print the combination.ExampleThe code shows the implementation of our code −#define MAX_POINT 3 #define ARR_SIZE ...

Read More

Program to print all substrings of a given string in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we will be discussing a program to print all the substring of a given string.For this we will be given with a string or an array of characters. Our task is to print all the substrings of that particular string.Example#include using namespace std; //printing all the substrings void print_substr(char str[], int n){    for (int len = 1; len

Read More

Find sum of digits in factorial of a number in C++

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

Suppose, we have a number n, our task is to find the sum of digits in then!. Consider n = 5, then n! = 120. So the result will be 3.To solve this problem, we will create a vector to store factorial digits and initialize it with 1. Then multiply 1 to n one by one to the vector. Now sum all the elements in the vector and return the sumExample#include #include using namespace std; void vectorMultiply(vector &v, int x) {    int carry = 0, res;    int size = v.size();    for (int i = 0 ; i ...

Read More

Program to print all the numbers divisible by 3 and 5 in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we will be discussing a program to print all the numbers divisible by 3 and 5 less than the given number.For this we will be given with a number say N. Our task is to print all the numbers less than N which are divisible by both 3 and 5.Example#include using namespace std; //printing the numbers divisible by 3 and 5 void print_div(int N){    for (int num = 0; num < N; num++){       if (num % 3 == 0 && num % 5 == 0)       cout

Read More

Print all combinations of factors in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 359 Views

In this problem, we are given a number n. Our task is to print all combinations of factors of n.Let’s take an example to understand the topic better −Input: 24 Output: 2 2 2 3 2 4 3 8 3 4 6 2 12For this, we will use recursion function which will find a combination of factors of the number. And we will store all our combinations in an array of array.ExampleThis code will show the implementation of our solution.#include using namespace std; vector factor_Combo; void genreateFactorCombinations(int first, int eachFactor, int n, vectorfactor) {    if (first>n || eachFactor>n)   ...

Read More

Find sum of sum of all sub-sequences in C++

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

Consider we have an array A with n elements. We have to find the total sum of the sum of all the subsets of the array. So if the array is like A = [5, 6, 8], then it will be like −SubsetSum5566885, 6116, 8145, 8135, 6, 819Total Sum76As the array has n elements, then we have a 2n number of subsets (including empty). If we observe it clearly, then we can find that each element occurs 2n-1 timesExample#include #include using namespace std; int totalSum(int arr[], int n) {    int res = 0;    for (int i = 0; ...

Read More

Find Tangent at a given point on the curve in C++

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

Suppose we have a curve like y = x(A - x), we have to find the tangent at a given point (x, y) on that curve. Here A is an integer number, x and y are also integers.To solve this, we have the check that the given point is on the curve or not, if so, then find the differentiation of that curve, so it will be −$$\frac{\text{d}y}{\text{d}x}=A-2x$$Then put x and y into the dy/dx, then find the tangent using this equation −$$Y-y=-\lgroup\frac{\text{d}y}{\text{d}x}\rgroup*\lgroup X-x \rgroup$$Example#include using namespace std; void getTangent(int A, int x, int y) {    int differentiation = ...

Read More

Maximum equlibrium sum in an array in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 539 Views

Problem statementGiven an array arr[]. Find maximum value of prefix sum which is also suffix sum for index i in arr[].ExampleIf input array is −Arr[] = {1, 2, 3, 5, 3, 2, 1} then output is 11 as −Prefix sum = arr[0..3] = 1 + 2 + 3 + 5 = 11 andSuffix sum = arr[3..6] = 5 + 3 + 2 + 1 = 11AlgorithmTraverse the array and store prefix sum for each index in array presum[], in which presum[i] stores sum of subarray arr[0..i]Traverse array again and store suffix sum in another array suffsum[], in which suffsum[i] stores ...

Read More
Showing 14411–14420 of 25,466 articles
Advertisements