Twisted question from interviewer, but not difficult.
for(; num > 0; sum += num%10, num /= 10);
printf(“Sum = %d\n”,sum);
or we can right like this
while((sum = sum+(num%10)) && (num = num/10) > 0);
Knowledge point
Twisted question from interviewer, but not difficult.
for(; num > 0; sum += num%10, num /= 10);
printf(“Sum = %d\n”,sum);
or we can right like this
while((sum = sum+(num%10)) && (num = num/10) > 0);