class Solution {

public:

int addDigits(int num) {

```
if(num < 10)
return num;
int a[10];
int i = 0;
while(num)
{
a[i++] = num%10;
num /= 10;
}
int temp = 0;
for(int j = 0;j < i;j++)
{
temp = temp + a[j];
}
while(temp > 9)
{
int a = temp %10;
int b = temp /10;
temp = a + b;
}
return temp;
}
```

};