Sum of digits https://www.codechef.com/problems/FLOW006

Is this code optimized or is there any other logic to solve this problem?
#include <stdio.h>

int main(void) {
int t;
scanf("%d",&t);
while(t–)
{
int sum=0,n;
scanf("%d",&n);
while(n)
{
sum=sum+n%10;
n=n/10;
}printf("%d\n",sum);
}
}

Yeah it’s all good and optimized!

1 Like