**solution1: loop**

```
class Solution {
public:
int addDigits(int num) {
while(num > 9) num = num / 10 + num % 10;
return num;
}
};
```

**solution2: math**

```
class Solution {
public:
int addDigits(int num) {
return (num - 1) % 9 + 1;
}
};
```