
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1060 Articles for PHP

181 Views
To find the sum of first n natural numbers that are divisible by a number ‘x’ or a number ‘y’, the code is as follows −Example Live DemoOutputThe sum of first 11 natural numbers divisible by 2 or 5 is 15A function named ‘sum_of_nums’ is defined that computes three values by checking if they can be divided by two specific values or not. Outside the function, the number and the two specific values are defined, and the function is called by passing these values as parameters. Relevant output is displayed on the console

565 Views
To find the numbers within a given array that are missing, the code is as follows −Example Live DemoOutputThe missing numbers in the array is 1 2 3 4 5A function named ‘missing_nums’ is defined that checks to see if a number is missing from an array of continuous numbers. It iterates through the array and checks to see the count and the current_num that is being iterated over. If two values can’t be found when 1 is added to the previous number, it is considered to be missing.Outside the function, the array is defined, its length is assigned to a ... Read More

211 Views
To find the first natural number whose factorial can be divided by a number ‘x’, the code is as follows −Example Live DemoOutputThe first natural number whose factorial can be divided by 16 is 4A function named ‘factorial_num’ computes factorial of a number and checks to see if it is divisible by 16, and if yes, returns that number as output. Outside the function, a number is defined and it is passed as parameter to the function. Relevant output is displayed on the console.

346 Views
To find if a number is present in a given sequence of numbers, the code is as follows −Example Live DemoOutputIs the number present in the sequence? Yes, it is present in the sequenceA function named ‘contains_in_sequence’ checks to see if two values are same, and if they are equal, the function returns true. If the difference between the two values multiplied by a third value is greater than 0 and the difference between the values divided by the third value gives a reminder as 0, the function returns true, otherwise, returns false. Values are assigned to the three variables and ... Read More

542 Views
To find the sum of cubes of the first n natural numbers, the code is as follows −Example Live DemoOutputThe sum of cubes of first 8 natural numbers is 1296A function named ‘sum_of_cubes’ is defined that initializes a sum to 0. Every natural number is multiplied by itself thrice (cube) and added to the initial sum. The limit is the value that is passed as a parameter to the function. The limit is defined outside the function and the function is called. Relevant output is displayed on the console.

387 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 of natural numbers that are not powers of a certain value. The number and the non-power number are passed as parameters to this function. Outside the function, a value each for n and k is defined and the function is called on these values. Relevant output is displayed on the ... Read More

204 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 every natural number up to a certain range is computed and added to the initial sum value. Outside the function, a value is defined and the function is called by passing this value as parameter. Relevant message is displayed on the console.

837 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 it by total numbers of values. This is the average of the first few natural numbers. A value is defined, and the function is called by passing this value, which is actually the limit up to which the average of numbers needs to be found. Relevant message is displayed on ... Read More

295 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 of every number needs to be found and each on them need to be added up. A ‘for’ loop is iterated over, and every number is cubed and added to an initial sum that was initially 0. The function is called by passing a number that is the limit as ... Read More