C++ problem

Please help me with this problem:-
Suppose a number N is 189. The sum of digits S is 1+8+9=18. Since S is not a unit digit number ( i.e. S>=10) So for next loop** S = 1+8=9**. So the solution that mohit comes up with will be 9.
Input Format

First line contain T testcases. Each T lines contain a number N.

Constraints

(1<=T<=10^5) (1<=N<=10^9)

Output Format

For Each T line print a single number S (1<=S<=9).

Sample Input 0

3
189
15
200
Sample Output 0

9
6
2

Though i have tried to code it but it seems to not work with other testcases.
Here is my code:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int ad(int long long);
int bh(int long long);


int main() {
int long long a[100000],b,c,sum,e,limit;
cin>>limit;
for(int i=1;i<=limit;i++)
{cin>>a[i];}
for(int i=1;i<=limit;i++)
{
sum=0;

while(a[i]!=0)
{
c=a[i]%10;
sum=sum+c;

a[i]=a[i]/10;
}

b=bh(sum);

if(b!=1)
{ e=ad(sum);
cout<<e<<"\n";
}
else
cout<<sum<<"\n";
}

return 0;
}
int bh(int long long a)
{
int i=0;
while(a!=0)
{
a=a/10;
i++;

}

return i;
}

int ad(int long long e)
{
int mod,sum=0;
while(e!=0)
{
mod=e%10;
e=e/10;
sum=sum+mod;
}
return sum;
}

Can somebody please help me?
Suppose a number N is 189. The sum of digits S is 1+8+9=18. Since S is not a unit digit number ( i.e. S>=10) So for next loop** S = 1+8=9**. So the solution that mohit comes up with will be 9.

First line contain T testcases. Each T lines contain a number N.


Can somebody please help me?

I don't know the problem you are having yet.
What does the word "mohit" mean?
"mohit" is a name in the problem. i am not able to get through with other testcases. that is my code is yunable to run with some integers. i wanted to check if my code is right.
Topic archived. No new replies allowed.