Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to make a histogram of an array in C++

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

In this tutorial, we will be discussing a program to make a histogram by the data given inside an array.For this, we will be provided with integer values inside an array. Our task is to plot a histogram keeping the value of both coordinates x and y equal to the value provided in the array.Example#include using namespace std; void make_histogram(int arr[], int n){    int maxEle = *max_element(arr, arr + n);    for (int i = maxEle; i >= 0; i--) {       cout.width(2);       cout

Read More

Find longest sequence of 1's in binary representation with one flip in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have one integer n. Inside that, we can make the one-bit flip to generate the longest sequence of 1s. Suppose the number is 13, so binary representation is 1101. If we make a one-bit flip as make 0 to 1, it will be 1111. This is the longest sequence of 1sTo solve this problem, we will walk through the bits of a given number. We will keep track of the current 1’s sequence length, and the previous 1’s sequence length. When a zero has found, then update the previous length. So if the next bit is 1, then ...

Read More

Find maximum level product in Binary Tree in C++

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

Suppose, one binary tree is given. It has positive and negative nodes. We have to find the maximum product at each level of it.Consider this is the tree, so the product of level 0 is 4, product of level 1 is 2 * -5 = -10, and product of level 2 is -1 * 3 * -2 * 6 = 36. So this is the maximum one.To solve this, we will perform the level order traversal of the tree, during traversal, process doing the nodes of different levels separately. Then get the maximum product.Example#include #include using namespace std; class Node ...

Read More

Find maximum product of digits among numbers less than or equal to N in C++

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

Suppose, we have one integer N > 0. The task is to find the maximum product of digits among numbers less than or equal to N. If the N is 390, then the result is 216, as the number 389 is making maximum product 3 * 8 * 9 = 216.To solve this problem, we will use the recursive approach. So if N = 0, then return 1, if the number N < 10, then return N, otherwise return max(max_product(N/10) * (N mod 10), max_product((N/10) - 1)*9)Example#include using namespace std; int max_product(int N) {    if (N == 0)   ...

Read More

Program to print 'N' alphabet using the number pattern from 1 to n in C++

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

In this tutorial, we will be discussing a program to print ‘N’ alphabet using the number pattern from 1 to n.For this we will have to print the english alphabet N. Our task is to determine the size of the letter and print it back using the numbers from 1 to n.Example#include using namespace std; //printing the letter N void print_N(int N){    int index, side_index, size;    int Right = 1, Left = 1, Diagonal = 2;    for (index = 0; index < N; index++) {       cout

Read More

Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++

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

Suppose we have four integers a, b, c and k. We have to find the minimum positive value x, such that the following equation satisfies −𝑎𝑥2+𝑏𝑥+𝑐 ≥𝑘If a = 3, b = 4, c = 5 and k = 6, then output will be 1To solve this, we will use the bisection approach. The lower limit will be 0 since x has to be a minimum positive integer.Example#include using namespace std; int getMinX(int a, int b, int c, int k) {    int x = INT8_MAX;    if (k

Read More

Program to print 2D shapes in C++

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

In this tutorial, we will be discussing a program to print out 2D shapes.For this we will be provided with the various parameters required to make a shape such as radius, side length and side breadth, etc. And our task is to print a shape accordingly with no thickness.Example#include using namespace std; void print_circle(int radius){    for (int i = 0; i

Read More

Replacing Array Elements in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 756 Views

Now we are going to introduce one more function called splice(), which has the following syntax −Syntaxsplice @ARRAY, OFFSET [ , LENGTH [ , LIST ] ]This function will remove the elements of @ARRAY designated by OFFSET and LENGTH, and replaces them with LIST if specified. Finally, it returns the elements removed from the array. Following is the example −Example#!/usr/bin/perl @nums = (1..20); print "Before - @nums"; splice(@nums, 5, 5, 21..25); print "After - @nums";OutputThis will produce the following result −Before - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

Read More

Transform Perl Arrays to Strings

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 10K+ Views

We can use the join() function in Perl to rejoin the array elements and form one long scalar string. This function has the following syntax −Syntaxjoin EXPR, LISTThis function joins the separate strings of LIST into a single string with fields separated by the value of EXPR and returns the string. Following is the example −Example#!/usr/bin/perl # define Strings $var_string = "Rain-Drops-On-Roses-And-Whiskers-On-Kittens"; $var_names = "Larry, David, Roger, Ken, Michael, Tom"; # transform above strings into arrays. @string = split('-', $var_string); @names = split(', ', $var_names); $string1 = join( '-', @string ); $string2 = join( ', ', @names ); ...

Read More

Sorting Arrays in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 899 Views

The sort() function in Perl sorts each element of an array according to the ASCII Numeric standards. This function has the following syntax −Syntaxsort [ SUBROUTINE ] LISTThis function sorts the LIST and returns the sorted array value. If SUBROUTINE is specified then specified logic inside the SUBROUTINE is applied while sorting the elements.Example#!/usr/bin/perl # define an array @foods = qw(pizza steak chicken burgers); print "Before: @foods"; # sort this array @foods = sort(@foods); print "After: @foods";OutputThis will produce the following result −Before: pizza steak chicken burgers After: burgers chicken pizza steakPlease note that sorting is performed based on the ...

Read More
Showing 28591–28600 of 61,297 articles
Advertisements