Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 522 of 2544
How to access an associative array by integer index in PHP?
To access an associative array by integer index in PHP, the code is as follows−ExampleOutputThis will produce the following output−Array key and value... key: p, value: 150 key: q, value: 100 key: r, value: 120 key: s, value: 110ExampleLet us now see another example−OutputThis will produce the following output−Array key and value... key: p, value: 150 key: q, value: 100 key: r, value: 120 key: s, value: 110 Updated Array key and value... key: p, value: 150 key: q, value: 100 key: r, value: 20 key: s, value: 10
Read MorePrint all Prime Quadruplet of a number less than it in C++
In this problem, we are given a positive integer N, and we have to print all prime quadruplet less than or equal to n.Prime quadruplets are the set of four prime numbers calculated as {p, p+2, p+6, p+8}. Example − 5 7 11 13.Let’s take an example to understand the problem −Input: N = 15 Output: 5 7 11 13.To solve this problem, a simple approach is to generate all quadruplets of prime number p and check if all p, p+2, p+6, p+8 are prime numbers. This solution is easy but is more complex for the compiler.Another efficient approach is ...
Read MoreGenerating Random String Using PHP
To generate random string using PHP, the code is as follows−ExampleOutputThis will produce the following output−Displaying random string... 1c856ExampleLet us now see another example −OutputThis will produce the following output−Displaying random string... a3541 Displaying another random string... 335b83d9e9
Read MoreDifference between !== and ==! operator in PHP
'!==' comparison operator'!==' operator checks the unequality of two objects with a type check. It does not converts the datatype and makes a typed check.For example 1 !== '1' will results true.'==!' comparison operator'==!' operator is combination of two operators and can be written as == (!operands).ExampleFollowing example, shows usage of '!==' vs '==!' operators. PHP Example Output$x !== operator $y = bool(true) $x ==! operator $y = bool(true)
Read MorePrint all prime numbers less than or equal to N in C++
In this problem, we are given a number N and we have to print all prime numbers less than or equal to N.Let’s take an example to understand the topic better −Input: 10 Output: 2 3 5 7A prime number is a number that can be divided by only one and the number itself. Example: 2, 3.A simple approach is to iterate from 2 to N and divide the number by it. If the number is not divisible, then it’s a prime number. Print the number. Do this till the number is equal to N. This approach is not that ...
Read MorePrint Binary Tree in 2-Dimensions in C++
In this problem, we are given a binary tree and we have to print it two dimensional plane.Binary Tree is a special tree whose every node has at max two child nodes. So, every node is either a leaf node or has one or two child nodes.Example, Let’s take an example to understand the topic better −Output - 7 4 5 1 3 8Now as we have seen in the example, the nodes of the tree are printed in a 2-D output screen horizontally.Here, we have flipped the tree by ...
Read MoreFinding a Match Within Another Match Java regular expressions
To match a pattern within another match you need to compile the regular expression to match the outer pattern find the match retrieve the results and pass the results as input to the inner Matcher object.Exampleimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherExample { public static void main(String[] args) { int start = 0, len = -1; Scanner sc = new Scanner(System.in); System.out.println("Enter input text: "); String input = sc.nextLine(); String regexOuter = "(.*?)"; String regexInner = "\d+"; ...
Read MorePrint all prime factors and their powers in C++
In this problem, we are given a number N, and we have to find all unique prime factors and their powers that divide the number.Let’s take an example to understand the topic −Input: 55 Output: 5 power 1 11 power 1Explanation −55 is divisible by 5 and 11.To solve this problem, an easy approach to solving the problem is to find prime factors of N. And then find power of the prime number that divides the number N and print it.AlgorithmEfficient ApproachStep 1: Find an array s[N+1]. s[i] = prime factor of i dividing N. Step 2: Find all powers ...
Read MoreC++ Program for Derivative of a Polynomial
Given a string containing the polynomial term, the task is to evaluate the derivative of that polynomial.What is a Polynomial?Polynomial comes from two words: - “Poly” which means “many” and “nomial” means “terms”, which comprises many terms. Polynomial expression is an expression containing variables, coefficients and exponents, which only involves operations such as, addition, multiplication and subtraction of variable(s).Example of polynomialx2+x+1Derivative of the polynomial p(x) = mx^n will be −m * n * x^(n-1)ExampleInput: str = "2x^3 +1x^1 + 3x^2" val = 2 Output: 37 Explanation: 6x^2 + 1x^0 + 6x^1 Putting x = 2 6*4 + ...
Read MorePrint array of strings in sorted order without copying one string into another in C++
In the problem to print an array of strings in sorted order without copying one string into another, we need to sort the array of string. Here the programmer cannot copy a string into another string while sorting.Let’s take an example to understand the concept better :Example −Input : {“Delhi”, “Hyderabad”, “Indore”, “Mumbai”, “Banglore”} Output : Banglore, Delhi, Hyderabad, Indore, MumbaiExplanation − Lexicographically the ordering is done. So, Bangalore starting with B comes first and Mumbai starting with M comes last.Now, let's try to derive a solution to our problem.To solve the problem, we can create an array that stores the ...
Read More