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));
}
Watch all videos like this

Leave a Reply

Your email address will not be published. Required fields are marked *