Programming Articles

Page 1247 of 2547

Count of common multiples of two numbers in a range in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

We are given two numbers A and B. Also provided two numbers START and END to define a range of numbers. The Ath tile has paint white and Bth tile has paint black. If the tile is painted both black and white then it turns grey. The goal is to find the total number of grey tiles .We will do this by traversing numbers from START to END and for each number we will check if the number is multiple of both A and B. If yes increment count.Let’s understand with examples.Input START=10 END=20 A=3 B=6Output Common multiples of A and B ...

Read More

How to create a covariance matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 767 Views

To create a covariance matrix, we first need to find the correlation matrix and a vector of standard deviations is also required. The correlation matrix can be found by using cor function with matrix object. For example, if we have matrix M then the correlation matrix can be found as cor(M). Now we can use this matrix to find the covariance matrix but we should make sure that we have the vector of standard deviations.Example1> M1 M1Output [, 1] [, 2] [, 3] ...

Read More

How to find the residual of a glm model in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

In a linear model, a residual is the difference between the observed value and the fitted value and it is not different for a general linear model. The difference between linear model and the general linear model is that we use a probability distribution to create a general linear model. If we want to find the residual for a general linear model then resid function can be used just like it is used with the linear model.Example1Consider the below data frame:> x1 y1 df1 df1Output x1 y1 1 4 2 2 3 3 3 5 3 4 4 2 5 ...

Read More

Count of numbers from range[L, R] whose sum of digits is Y in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 418 Views

We are provided two numbers START and END to define a range of numbers.The goal is to find all the numbers in the range [START, END] which have sum of digits equal to a given number Y.We will do this by traversing numbers from START to END and for each number we will count the sum of its digit using a while loop. If this sum is equal to Y, increment count.Let’s understand with examples.Input START=10 END=20 Y=4Output Numbers such that digit sum is equal to Y: 1Explanation Number 13 has digit sum equal to 4.Input START=10 END=50 Y=5Output Numbers such that digit sum is ...

Read More

How to create a bar chart using plotly in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 488 Views

Plotly in R is a package specifically designed to create highly-interactive and publication-quality charts. The chart can be created by using plot_ly function of the package and there are three main arguments of plot_ly defined as x, y, and type, where x refers to the X-axis, y refers to the Y-axis and type refers to the chart type but the axes values are stored in a data frame or itself a shared.ExampleLoading plotly package:> library(plotly)Consider the below data frame:> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Creating the bar plot for ...

Read More

Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 506 Views

We are provided two numbers START and END to define a range of numbers.The goal is to find all the numbers in the range [START, END] which have no digit as 0 and have sum of digits equal to a given number N. Also the numbers are divisible by MWe will do this by traversing numbers from START to END and for each number we will count the sum of its digit using a while loop ( only if all digits are non zero ). If this sum is equal to N and the number is divisible by M, increment ...

Read More

How to display the curve on the histogram using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

Mostly, we use histogram to understand the distribution of a variable but if we have an overlay line on the histogram that will make the chart smoother, thus understanding the variation will become easy. To display the curve on the histogram using ggplot2, we can make use of geom_density function in which the counts will be multiplied with the binwidth of the histogram so that the density line will be appropriately created.ExampleConsider the below data frame:> x df head(df, 20)Output x 1 4 2 5 3 6 4 4 5 9 6 ...

Read More

How to create a vector of lists in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 638 Views

If we have many lists but we want to use the values in the lists as a vector then we first need to combine those lists and create a vector. This can be done by using unlist function along with the combine function c to create the vector. For example, if we have two lists defined as List1 and List2 and we want to create a vector V using these lists then it can be created as:V x1 x1Output$a [1] -0.6972237 -1.5013768 -0.2451809 -0.2365569 -1.6304919 -1.1704378 [7] 1.1617054 -0.2349498 -1.2582229 0.4112065 $b [1] 2 0 2 6 0 0 ...

Read More

Count ordered pairs of positive numbers such that their sum is S and XOR is K in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 361 Views

We are given two numbers S and K. The goal is to find ordered pairs of positive numbers such that their sum is S and XOR is K.We will do this by starting from i=1 to i

Read More

How to replace a sub-string with the reverse of that sub-string in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 202 Views

The chartr function in base R helps us to replace old strings with new strings and hence it can be also used to replace a subs-string with the reverse of that substring. For example, if we have a vector say x that contains tutorialpsoint and we want to convert it to tutorialspoint then it can be done as chartr("tutorialpsoint ", " tutorialspoint ", x).Example1> x1 x1Output[1] "IDNIA"Example> chartr("DN", "ND", x1)Output[1] "INDIA" Example2> x2 x2Output[1] "IDNIA" "IDNIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNONESIA" [7] "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNIA" "IDNONESIA" [13] "IDNONESIA" "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNIA" [19] "IDNONESIA" "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" ...

Read More
Showing 12461–12470 of 25,466 articles
Advertisements