Articles on Trending Technologies

Technical articles with clear explanations and examples

Private Variables in a Subroutine in Perl

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

By default, all variables in Perl are global variables, which means they can be accessed from anywhere in the program. But you can create private variables called lexical variables at any time with the my operator.The my operator confines a variable to a particular region of code in which it can be used and accessed. Outside that region, this variable cannot be used or accessed. This region is called its scope. Lexical scope is usually a block of code with a set of braces around it, such as those defining the body of the subroutine or those marking the code ...

Read More

Find the area of largest circle inscribed in ellipse in C++

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

Suppose we have an ellipse, with major and minor axis length 2a & 2b. We have to find the area of the largest circle that can be inscribed in it. So if the a = 5 and b = 3, then area will be 28.2734From the we can see that the radius of the maximum area circle inscribed in an ellipse will be the minor axis ‘b’. So the area will be A = π*b*bExample#include using namespace std; double inscribedCircleArea(double b) {    double area = 3.1415 * b * b;    return area; } int main() {    double a = 10, b = 8;    cout

Read More

Temporary Values via local() in Perl

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

The local is mostly used when the current value of a variable must be visible to called subroutines in Perl. A Perl local just gives temporary values to global (meaning package) variables. This is known as dynamic scoping. Lexical scoping is done with my, which works more like C's auto declarationsIf more than one variable or expression is given to local, they must be placed in parentheses. This operator works by saving the current values of those variables in its argument list on a hidden stack and restoring them upon exiting the block, subroutine, or eval.ExampleLet's check the following example ...

Read More

Find the count of maximum contiguous Even numbers in C++

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

Suppose we have an array A with n elements. We have to find the maximum number of the contiguous even numbers in the given array. So if the array is like A = [1, 2, 3, 4, 6, 8, 7], then the count will be 3.We can solve this easily. We need two count variables one is max_current, and another is max_till_now. If an even number is found, then increase max_current, then compare it with max_till_now. Every time an odd element is found reset max_count to 0.Example#include using namespace std; int maxEvenContiguous(int arr[], int n) {    int max_current = ...

Read More

State Variables via state() in Perl

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

There is another type of lexical variable in Perl, which is similar to private variables but they maintain their state and they do not get reinitialized upon multiple calls of the subroutines. These variables are defined using the state operator and available starting from Perl 5.9.4.ExampleLet's check the following example to demonstrate the use of state variables −#!/usr/bin/perl use feature 'state'; sub PrintCount {    state $count = 0; # initial value    print "Value of counter is $count";    $count++; } for (1..5) {    PrintCount(); }OutputWhen the above program is executed, it produces the following result −Value of ...

Read More

Find the final radiations of each Radiated Stations in C++

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

Suppose there are N stations in the straight line. Each of them has same non-negative power of radiation power. Every station can increase the radiation power of its neighboring stations in the following way.Suppose the station i with radiation power R, will increase (i – 1)th station’s radiation power, by R-1, (i - 2)th station’s radiation power by R-2, and will increase (i + 1)th station’s radiation power, by R-1, (i + 2)th station’s radiation power by R-2. So on. So for example, if the array is like Arr = [1, 2, 3], then the output will be 3, 4, ...

Read More

Find the first circular tour that visits all petrol pumps in C++

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

Suppose there is a circle, and there are n petrol pumps on the circle. We have two sets of data like −The amount of petrol that every petrol pump hasDistance from one petrol pump to anotherCalculate the first point, from where a truck will be able to complete the circle. Assume for 1 liter petrol, the truck can go 1 unit of distance. Suppose there are four petrol pumps, and the amount of petrol, and distance from the next petrol pump is as like [(4, 6), (6, 5), (7, 3), (4, 5)], the first point from where truck can make ...

Read More

Dereferencing in Perl

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

Dereferencing in Perl returns the value from a reference point to the location. To dereference a reference simply use $, @ or % as a prefix of the reference variable depending on whether the reference is pointing to a scalar, array, or hash. Following is the example to explain the concept −Example#!/usr/bin/perl $var = 10; # Now $r has reference to $var scalar. $r = \$var; # Print value available at the location stored in $r. print "Value of $var is : ", $$r, ""; @var = (1, 2, 3); # Now $r has reference to @var ...

Read More

Find the maximum element in an array which is first increasing and then decreasing in C++

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

Suppose we have one array, which is initially increasing then decreasing. We have to find the max value in the array. So if the array elements are like A = [8, 10, 20, 80, 100, 250, 450, 100, 3, 2, 1], then output will be 500.We can use the binary search to solve this. There are three conditions −When mid is greater than both of its adjacent elements, then mid is maximumIf mid is greater than the next element, but smaller than previous element, then max lies on the left side of mid.If mid element is smaller than the next ...

Read More

Circular References in Perl

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

A circular reference in Perl occurs when two references contain a reference to each other. You have to be careful while creating references otherwise a circular reference can lead to memory leaks. Following is an example −Example#!/usr/bin/perl my $foo = 100; $foo = \$foo; print "Value of foo is : ", $$foo, "";OutputWhen the above program is executed, it produces the following result −Value of foo is : REF(0x9aae38)

Read More
Showing 28631–28640 of 61,297 articles
Advertisements