Articles on Trending Technologies

Technical articles with clear explanations and examples

Multiline Strings in Perl

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

If you want to introduce multiline strings into your programs, you can use the standard single quotes as below −Example#!/usr/bin/perl $string = 'This is a multiline string'; print "$string";OutputThis will produce the following result −This is a multiline stringYou can use "here" document syntax as well to store or print multiline as below −Example#!/usr/bin/perl print

Read More

Find the number of jumps to reach X in the number line from zero in C++

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

Suppose we have an integer X. We have to find minimum number of jumps required to reach X from 0. The first jump made can be of length one unit and each successive jump will be exactly one unit longer than the previous jump in length. It is allowed to go either left or right in each jump. So if X = 8, then output is 4. 0 → -1 → 1→ 4 → 8 are possible stages.If we observe carefully, then we can say thatIf you have always jumped in the right direction, then after n jumps you will ...

Read More

V-Strings in Perl

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

A literal of the form v1.20.300.4000 is parsed as a string composed of characters with the specified ordinals. This form is known as v-strings.A v-string provides an alternative and more readable way to construct strings, rather than use the somewhat less readable interpolation form "\x{1}\x{14}\x{12c}\x{fa0}".They are any literal that begins with a v and is followed by one or more dot-separated elements. For example −Example#!/usr/bin/perl $smile = v9786; $foo = v102.111.111; $martin = v77.97.114.116.105.110; print "smile = $smile"; print "foo = $foo"; print "martin = $martin";OutputThis will also produce the same result −smile = ☺ foo = foo martin = ...

Read More

Find distance between two nodes of a Binary Tree in C++

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

Consider we have a binary tree with few nodes. We have to find the distance between two nodes u and v. suppose the tree is like below −Now the distance between (4, 6) = 4, path length is 4, length between (5, 8) = 5 etc.To solve this problem, we will find the LCA (Lowest Common Ancestor), then calculate distance from LCA to two nodes.Example#include using namespace std; class Node {    public:       int data;    Node *left, *right; }; Node* getNode(int data) {    Node* node = new Node;    node->data = data;    node->left = ...

Read More

Find the frequency of a digit in a number using C++.

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

Here we will see how to get the frequency of a digit in a number. Suppose a number is like 12452321, the digit D = 2, then the frequency is 3.To solve this problem, we take the last digit from the number, then check whether this is equal to d or not, if so then increase the counter, then reduce the number by dividing the number by 10. This process will be continued until the number is exhausted.Example#include using namespace std; int countDigitInNum(long long number, int d) {    int count = 0;    while(number){       if((number % ...

Read More

Perl Special Literals

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

Let me tell you about three special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that point in your program.They may be used only as separate tokens and will not be interpolated into strings. Check the below example −Example#!/usr/bin/perl print "File name ". __FILE__ . ""; print "Line Number " . __LINE__ .""; print "Package " . __PACKAGE__ .""; # they can not be interpolated print "__FILE__ __LINE__ __PACKAGE__";OutputThis will produce the following result −File name hello.pl Line Number 4 Package main __FILE__ __LINE__ __PACKAGE__

Read More

Find the number of ways to divide number into four parts such that a = c and b = d in C++

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

Suppose we have a number n. We have to find number of ways to divide a number into parts (a, b, c and d) such that a = c, and b = d. So if the number is 20, then output will be 4. As [1, 1, 9, 9], [2, 2, 8, 8], [3, 3, 7, 7] and [4, 4, 6, 6]So if N is odd, then answer will be 0. If the number is divisible by 4, then answer will be n/4 – 1 otherwise n/4.Example#include using namespace std; int countPossiblity(int num) {    if (num % 2 == 1)       return 0;    else if (num % 4 == 0)       return num / 4 - 1;    else       return num / 4; } int main() {    int n = 20;    cout

Read More

Find distance from root to given node in a binary tree in C++

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

Consider we have a binary tree with few nodes. We have to find the distance between the root and another node u. suppose the tree is like below:Now the distance between (root, 6) = 2, path length is 2, distance between (root, 8) = 3 etc.To solve this problem, we will use a recursive approach to search the node at the left and right subtrees, and also update the lengths for each level.Example#include using namespace std; class Node {    public:       int data;    Node *left, *right; }; Node* getNode(int data) {    Node* node = new ...

Read More

Find the Product of first N Prime Numbers in C++

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

Suppose we have a number n. We have to find the product of prime numbers between 1 to n. So if n = 7, then output will be 210, as 2 * 3 * 5 * 7 = 210.We will use the Sieve of Eratosthenes method to find all primes. Then calculate the product of them.Example#include using namespace std; long PrimeProds(int n) {    bool prime[n + 1];    for(int i = 0; i

Read More

Accessing Array Elements in Perl

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

When accessing individual elements from an array in Perl, you must prefix the variable with a dollar sign ($) and then append the element index within the square brackets after the name of the variable. For example −Example#!/usr/bin/perl @days = qw/Mon Tue Wed Thu Fri Sat Sun/; print "$days[0]"; print "$days[1]"; print "$days[2]"; print "$days[6]"; print "$days[-1]"; print "$days[-7]";OutputThis will produce the following result −Mon Tue Wed Sun Sun MonArray indices start from zero, so to access the first element you need to give 0 as indices. You can also give a negative index, in which case you select the ...

Read More
Showing 28561–28570 of 61,297 articles
Advertisements