KodeGod.com

023. Technical interview question: Find the sum of digits using single statement

#include<stdio.h>
int sum(int x)
        {
         int s;
         for( s=0 ; x>0 ; s+=x%10 , x/=10);
         return s;
        }
int main ()
{
    printf("%d", sum(143));
}