AmitDiwan has Published 10740 Articles

PHP program to find the sum of the first n natural numbers who are not powers of a specific number ‘k’

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 07:05:04

437 Views

To find the sum of the first n natural numbers who are not powers of a specific number ‘k’, the code is as follows −Example Live DemoOutputThe sum of fist 20 natural numbers that are not powers of 3 is 198A function named ‘sum_of_nums’ is defined and it calculates the sum ... Read More

PHP program to find the sum of the 5th powers of first n natural numbers

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 07:03:38

239 Views

To find the sum of the 5th powers of first n natural numbers, the code is as follows −Example Live DemoOutputThe sum of fifth powers of the first n natural numbers is 85648386825A function named ‘sum_of_fifth_pow’ is defined, and an initial sum value is defined as 0. The fifth power of ... Read More

PHP program to find the average of the first n natural numbers that are even

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 07:02:20

864 Views

To find the average of the first n natural numbers that are even, the code is as follows −Example Live DemoOutputThe average of the first n natural numbers that are even is 12A function named ‘even_nums_avg’ is defined that adds up all the numbers up to a given limit, and divides ... Read More

PHP program to find the sum of cubes of natural numbers that are odd

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 07:01:25

326 Views

To find the sum of cubes of natural numbers that are odd, the code is as follows −Example Live DemoOutputThe sum of cubes of first 8 natural numbers that are even is 3968A function named ‘sum_of_cubes_even’ is defined that takes a limit on the natural number up to which the cube ... Read More

PHP program to check if all digits of a number divide it

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 07:00:08

274 Views

To check if all digits of a number divide it in PHP, the code is as follows −Example Live Demo

PHP program to check if the total number of divisors of a number is even or odd

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:58:31

258 Views

To check if the total number of divisors of a number is even or odd, the code is as follows −Example Live DemoOutputIt is an odd numberA function named ‘divisor_count’ is defined that gives the number of divisors of a given number that is passed as a parameter to the function. ... Read More

Is there any alternative for CONCAT() in MySQL?

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:55:49

1K+ Views

Yes, an alternative is CONCAT_WS(). Let us first create a table −mysql> create table DemoTable    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100)    ); Query OK, 0 rows affected (0.74 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('Chris'); ... Read More

PHP program to split a given comma delimited string into an array of values

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:54:26

2K+ Views

To split a given comma delimited string into an array of values, the PHP code is as follows −Example Live DemoOutputThe array is Array (    [0] => 456    [1] => 789    [2] => 23    [3] => 4    [4] => 019 ) The array is Array ( ... Read More

PHP program to remove non-alphanumeric characters from string

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:53:14

1K+ Views

To remove non-alphanumeric characters from string, the code is as follows −Example Live DemoOutputThe non-alphanumeric characters removed gives the string as ThisissampleonlyThe function ‘preg_replace’ is used to remove alphanumeric characters from the string. A regular expression is used to filter out the alphanumeric characters. The string is previously defined and the ... Read More

Select query to display duplicate values with max date

AmitDiwan

AmitDiwan

Updated on 02-Jul-2020 06:53:00

1K+ Views

For this, use GROUP BY and HAVING. Let us first create a table −mysql> create table DemoTable    (    StudentName varchar(100),    DueDate date    ); Query OK, 0 rows affected (0.72 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('John', '2019-01-11'); Query OK, ... Read More

Advertisements