Saturday, December 5, 2009

How can we sum the digits of a given number in single statement?

int sum=0;

  for(;num>0;sum+=num%10,num/=10);  // This is the "single line".

No comments:

Post a Comment