0 votes
144 views
in Discuss by (3.5k points)
edited
Write a PHP program to print sum of digits.

1 Answer

0 votes
by (3.5k points)
selected by
 
Best answer
  1. <?php  
  2. $num = 14597;  
  3. $sum=0; $rem=0;  
  4.   for ($i =0; $i<=strlen($num);$i++)  
  5.  {  
  6.   $rem=$num%10;  
  7.    $sum = $sum + $rem;  
  8.    $num=$num/10;  
  9.   }  
  10.  echo "Sum of digits 14597 is $sum";  
  11.  ?>  

Related questions

0 votes
1 answer 419 views
0 votes
1 answer 118 views
0 votes
1 answer 131 views
asked Aug 21, 2022 in Discuss by codelikepro (3.5k points)
0 votes
1 answer 165 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...