d_r_sriram Posted April 22, 2009 Share Posted April 22, 2009 Hi Everybody-I have to implement a code that adds up 8 digits amongst itself till it doesnt get reduced to a single digit. for ex : i have to add 31031976 as 3+1+0+3+1+9+7+6=30=3+0=3.the input wud be always of 8 digits.can someone be kind enof to share the code..thanks in advance-Sriram Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted April 22, 2009 Share Posted April 22, 2009 I posted a solution to this a few weeks ago. <?php $number = 31031976; while($number > 9) { $number = array_sum(str_split($number)); } echo $number; From: http://www.phpfreaks.com/forums/index.php/topic,247632.msg1158771.html#msg1158771 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.