This is a simple PHP program where we need to calculate the sum of all digits of a number.
Input : 711 Output : 9 Input : 14785 Output : 25
In this program, we will try to accept a number in the form of a string and then iterate through the length of the string. While iterating we will extract the digit from each position and then add them to the previously extracted digit, thus getting the sum.
- PHP | Check if a number is armstrong number
- PHP | Check if a number is Perfect number
- PHP | check if a number is Even or Odd
- PHP | Factorial of a number
- AngularJS | number Filter
- What is the difference between parseInt() and Number()?
- How to convert number to month name in PHP?
- How to convert a string into number in PHP?
- How to format a number as currency using CSS ?
- PHP | Check if a number is prime
- CSS | Number Data Type
- How to get the number of pages in a PDF document using PHP ?
- What is the use of number after “break” or “continue” statements in PHP ?