Programming Articles - Page 911 of 3363

Reverse and Add Function in Java

Sunidhi Bansal
Updated on 03-Nov-2021 08:02:33

714 Views

We are given with an integer and the agenda here is to reverse the digits of the number and add the reversed number to the original number and check if the resultant number is a palindrome or not and the process is repeated until it does. The breaking point of the process is 1000 iterations and a value greater than the maximum long value( Long.MAX_VALUE).For ExamplesInput − 1678Output − Palindrome of the given input 1678 293392Explanation − The input number is first reversed and then added to the original number, it is then checked for palindrome if it is not a palindrome ... Read More

Recursive sum of digits of a number is prime or no in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:40:46

638 Views

Given an integer variable number as input. The goal is to calculate the sum of digits of the input number and check if that sum is prime or not. Do this till the obtained number with sum of digits becomes a single digit number. Check if that number is prime or not. If the input number is 123 than the sum of digits will be 1+2+3=6 which is non-prime and also 6 is a single digit number.Let us see various input output scenarios for thisInput − number=12341Output − Recursive sum of digits of a number is PRIMEExplanation −1+2+3+4+1=111+1=22 is a prime number.Input − ... Read More

How to make all values in an R data frame unique?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:41:54

539 Views

To make all values in an R data frame unique, we can use make.unique function but firstly we would need to unlist the data frame values and read them with as.character. For Example, if we have a data frame called df that contains duplicate as well as nonduplicate values then we can make all the values unique by using the below command −df[]

Recursive sum of digits of a number formed by repeated appends in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:36:06

432 Views

Given two integers ‘number’ and ‘repeat’ as input. The goal is to calculate the sum of digits of the input number repeated ‘repeat’ number of times until the sum becomes a single digit. Do this till the obtained number with sum of digits becomes a single digit number. If the input number is 123 and repeat=2 than the sum of digits of 123123 will be 1+2+3+1+2+3=12 which is not a single digit number. Now the sum of digits of 12 is 1+2=3. Output will be 3Let us see various input output scenarios for thisInput − number=32 repeat=3Output − Recursive sum of digits ... Read More

How to remove question mark from corrplot in R?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:35:41

2K+ Views

When we have NAs present in the data frame or matrix then correlation matrix contains NA values. Now if we create the correlation matrix plot using corrplot function the Output display question marks.If we want to create the correlation matrix without question marks then we can use the na.label argument and set it to blank as shown in the below Example.ExampleFollowing snippet creates a sample matrix −M

Recursively print all sentences that can be formed from list of word lists in C++

Sunidhi Bansal
Updated on 03-Nov-2021 08:14:36

589 Views

Given a list of words. The goal is to create all possible sentences that can be formed by taking words from the list using a recursive approach. You can only take one word at a time from both the lists.Let us see various input output scenarios for thisInput −sentence[row][col] = {{"I", "You"},    {"Do", "do not like"},    {"walking", "eating"}}Output   −I Do walking I Do eating I like walking I like eating You Do walking You Do eating You like walking You like eatingExplanation − Taking one word from each list in sentence[0-2] gives above sentences.Input −sentence[row][col] = {{"work", "live"}, {"easy", "happily"}}Output −work ... Read More

Rotate a matrix by 90 degree without using any extra space in C++

Sunidhi Bansal
Updated on 03-Nov-2021 08:41:32

587 Views

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in an anti-clockwise direction such that the first row becomes the first column, second row becomes second column and third becomes third column and the challenge is that we don’t have to use any extra space.Let us see various input output scenarios for this −Input −int arr[row_col_size][row_col_size] = { { 5, 1, 4},    { 9, 16, 12 },    { 2, 8, 9}}Output   −Rotation of a matrix by 90 degree without using any extra space ... Read More

How to find the row corresponding to a nearest value in an R data frame?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 07:40:32

4K+ Views

To find the row corresponding to a nearest value in an R data frame, we can use which.min function after getting the absolute difference between the value and the column along with single square brackets for subsetting the row.To understand how it works, check out the examples given below.Example 1Following snippet creates a sample data frame −ID

Rotate a matrix by 90 degree in clockwise direction without using any extra space in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:23:33

3K+ Views

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in a clockwise direction such that the last row becomes the first column, second row becomes second column and first becomes third column and the challenge is that we don’t have to use any extra space.Let us see various input output scenarios for this −Input −int arr[row_col_size][row_col_size] = { { 5, 1, 4},    { 9, 16, 12 },    { 2, 8, 9}}Output −Rotation of a matrix by 90 degree in clockwise direction without using any ... Read More

Refactorable number in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:19:18

191 Views

We are given an integer type value, let's say, number. The task is to check whether the given number is Refactorable or not. If yes print that the number is a refactorable number else print not possible.What is a Refactorable Number?A number is refactorable when it is divisible by its total count of factors available. For example, number 9 is refactorable as it has a total number of factors i.e. 3(1, 3, 9) and 9 is divisible by 3 hence its a refactorable number.Let us see various input output scenarios for this −Input − int number = 9Output − It is a ... Read More

Advertisements