The C library function char *strcat(char *dest, const char *src) appends the string pointed to by src to the end of the string pointed to by dest.An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strcat( ) functionThis is used for combining or concatenating two strings.The length of ... Read More
The C library function char *strncpy(char *dest, const char *src, size_t n) copies up to n characters from the string pointed to, by src to dest. In a case where, the length of src is less than that of n, the remainder of dest will be padded with null bytes.An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string ... Read More
The C library function char *strcpy(char *dest, const char *src) copies the string pointed to, by src to dest.An array of characters is called a string.DeclarationFollowing is the declaration for an arraychar stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’The strcpy ( ) functionThis function is used for copying source string into destination string.The length of the destination string is greater than ... Read More
The C library function size_t strspn(const char *str1, const char *str2) calculates the length of the initial segment of str1 which consists entirely of characters in str2.An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The Strspn() functionThis function search for specified string in the given string and returns ... Read More
The C library function int strcoll(const char *str1, const char *str2) compares string str1 to str2. The result is dependent on the LC_COLLATE setting of the location.An array of characters is called a stringDeclarationGiven below is the declaration of an array −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’The Strcoll() FunctionThis function is same as strcmp() function, it compares two strings ... Read More
Range SumRange sum rangeSum(i, j) is defined as the sum of the elements in an array between indices i and j (i ≤ j), inclusive.ProblemWe are required to write a JavaScript function that takes in an array of Integers, arr, as the first argument and two numbers, upper and lower as the second and third element.Our function is supposed to return the number of range sums that lie between the range [upper, lower], (both inclusive).For example, if the input to the function is −const arr = [1, 4, 3]; const upper = 5; const lower = 2;Then the output should ... Read More
Increasing SequenceA sequence of numbers in which each succeeding element is either greater or equal to the preceding element is an increasing sequence.For instance, 4, 6, 8, 9, 11, 14 is increasing sequence 3, 3, 3, 3, 3, 3, 3 is also an increasing sequenceProblem:We are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the only argument. Our function should find and return the length of that longest path in the array that contains only increasing numbers.For example, if the input to the function is −const arr = [ [4, 5, ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of Numbers, arr, as the first argument and a single number, num, as the second argument.We should, by adding elements to it, make our array such that any sum can be obtained by adding specific numbers from it between [0, num] (including both). Our function should finally return the minimum number of numbers required to add to the array so that it can produce any sum between 0 and num.For example, if the input to the function is −const arr = [1, 5, 10]; const sum = ... Read More
Increasing Numbers:A sequence of numbers in which each succeeding element is either greater or equal to the preceding element is an increasing sequence.For instance, 4, 6, 8, 9, 11, 14 is increasing sequence 3, 3, 3, 3, 3, 3, 3 is also an increasing sequenceProblemWe are required to write a JavaScript function that takes in an array of Numbers, arr, as the only argument. The function should check whether there exist three consecutive elements in the array that are increasing.For example, if the input to the function is −const arr = [4, 1, 5, 7, 3, 1, 4];Then the output ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of strings as the only argument. The function is supposed to return an array of arrays of all the index pairs joining the strings at which yields a new palindrome string.For example, if the input to the function is −const arr = ['tab', 'cat', 'bat'];Then the output should be −const output = [[0, 2], [2, 0]];Output Explanation:Because both the strings ‘battab’ and ‘tabbat’ are palindromes.ExampleThe code for this will be −const arr = ['tab', 'cat', 'bat']; const isPalindrome = (str = '') => { let i ... Read More