Why is my solution is wrong for practice Question FLOW006

#include<stdio.h>
main()
{
int t,i,n,sum=0;
scanf("\n%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
sum=0;
while(n!=0)
{
sum=sum+n%10;
n=n/10;
}
printf("\n%d",sum);
}
return 0;
}

You are not taking inputs and printing outputs in the defined format as is highlighted in the problem description.

Change scanf("\n%d",&t) to scanf("%d",&t) and printf("\n%d",sum); to printf("%d\n",sum);

1 Like

#include<stdio.h>
main()
{
int t,i,n;
scanf("\n%d",&t);
while(t–)
{
int sum=0;
scanf("%d",&n);

while(n!=0)
{
sum=sum+n%10;
n=n/10;
}
printf("\n%d",sum);
}
return 0;
}

idk the problem… but i had same issue but i noticed what i did wrong every time …
i tried it with ur code too… and it worked… if u know the issue pls tell me too…
Mainly the problem is with declaratin of sum . if u declare it in while loop its fine otherwise error and if u use for loop instead of while for testcases it gives error …

this is what i figured…