why it gives wrong answer

#include
using namespace std;
int main()
{
int t;
int a,no,sum=0;
cin>>t;
while(t–)
{
cin>>no;
while(no>0)
{
a=no%10;
no=no/10;
sum=sum+a;
}
cout<<sum<<endl;
}
}

You have to make sum=0 in every test case so that previous answers do not add into current one . So in the while loop of the , add sum=0 .