Programming Articles

Page 4 of 2545

How to replace blanks in a vector with the previous element in R?

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

Filling of blanks is not an easy task in data analysis, especially if the vector contains numerical or integer values. Suppose we have a vector x that contains 1, , 2, 3, 4, 5 and we want to put 1 in place of blank after first value then cummax function along with seq_along function can be used as x[cummax(seq_along(x)*(x!=""))].Example1x1

Read More

How to calculate mahalanobis distance in R?

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

The Mahalanobis distance is the relative distance between two cases and the centroid, where centroid can be thought of as an overall mean for multivariate data. We can say that the centroid is the multivariate equivalent of mean. If the mahalanobis distance is zero that means both the cases are very same and positive value of mahalanobis distance represents that the distance between the two variables is large. In R, we can use mahalanobis function to find the malanobis distance.Example1y1

Read More

PHP – How to cut out part of a string using iconv_substr()?

Urmila Samariya
Urmila Samariya
Updated on 11-Mar-2026 306 Views

In PHP, the iconv_substr() function is used to cut a portion of a specified string by the offset and length parameters. Suppose we have a string "helloWorld" and we want to cut and show only the string (llowo), then we will select it by using numbers from 2 to 5.Syntaxstring iconv_substr(str $string, int $offset, int $length, str $encoding)Parametersiconv_substr() accepts four parameters: $string, $offset, $length and $encoding.$string− The $string parameter specifies the original string.$offset− If the $offset parameter is non-negative, then the iconv_substr() function cuts the selected portion of the string from beginning at offset character, counting from zero. And if ...

Read More

How to Title Case a sentence in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 11-Mar-2026 10K+ Views

Title Case a sentence in javascriptIt is nothing but converting first element of all the words in a sentence in to uppercase while the other elements remain in lowercase. The provided string(sentence) may contains a bunch of lowercase and uppercase elements. So we need an algorithm to Title Case the provided string.AlgorithmDivide all the words in the sentence individually. This task can be achieved by using string.split() method.Convert all the elements in each and every word in to lowercase using string.toLowerCase() method. Loop through first elements of all the words using for loop and convert them in to uppercase. After converting, ...

Read More

Delete a file in C#

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 1K+ Views

Use File.Delete method to delete a file.Firstly, set the path of the file you want to delete.String myPath = @"C:\New\amit.txt";Now, use the File.Delete method to delete the file.File.Delete(myPath);The following is the complete code −Exampleusing System; using System.IO; public class Program {    public static void Main() {       String myPath = @"C:\New\amit.txt";       Console.WriteLine("Deleting File");       File.Delete(myPath);    } }OutputDeleting File

Read More

C program to Replace a word in a text by another given word

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 6K+ Views

In this program, we have given three strings txt, oldword, newword. Our task is to create a C program to replace a word in a text by another given word.The program will search for all the occurrences of the oldword in the text and replace it with newword.Let’s take an example to understand the problem −Inputtext = “I am learning programming” oldword = “learning” newword = “practicing”Output“I am practicing programming”To solve this problem, we will first find the number of occurrence of the oldword in the string and then create a new string which will store the text with replaced ...

Read More

Count all elements in the array which appears at least K times after their first occurrence in C++

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

In this tutorial, we will be discussing a program to find the number of elements in the array which appears at least K times after their first occurrence.For this we will be provided with an integer array and a value k. Our task is to count all the elements occurring k times among the elements after the element in consideration.Example#include #include using namespace std; //returning the count of elements int calc_count(int n, int arr[], int k){    int cnt, ans = 0;    //avoiding duplicates    map hash;    for (int i = 0; i < n; i++) ...

Read More

Java program to sort words of sentence in ascending order

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 5K+ Views

To sort words of sentence in ascending order, the Java code is as follows −Exampleimport java.util.*; public class Demo{    static void sort_elements(String []my_str, int n){       for (int i=1 ;i= 0 && temp.length() < my_str[j].length()){             my_str[j+1] = my_str[j];             j--;          }          my_str[j+1] = temp;       }    }    public static void main(String args[]){       String []my_arr = {"This", "is", "a", "sample"};       int len = my_arr.length;       sort_elements(my_arr,len);       System.out.print("The sorted array is : ");       for (int i=0; i

Read More

Length of Longest Fibonacci Subsequence in C++

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

Suppose we have a sequence X_1, X_2, ..., X_n is fibonacci-like if −n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 = 3 otherwise return 0.Let us see the following implementation to get better understanding −Example#include using namespace std; class Solution {    public:    int lenLongestFibSubseq(vector & A) {       int ret = 0;       unordered_map m;       int n = A.size();       vector < vector > dp(n, vector (n));       for(int i = 0; i < n; i++){         ...

Read More

What is the difference between ordered factors and unordered factors in R?

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

To understand the difference ordered factors and unordered factors, it is better to understand them by creating the factor vectors by using ordered argument with TRUE and FALSE options. For example, if we have a vector x then it can be ordered or unordered as factor(x,ordered=TRUE) and factor(x,ordered=FALSE).Example1x1

Read More
Showing 31–40 of 25,445 articles
Advertisements