```
#include <iostream>
```

using namespace std;

class Solution {

public:

int addDigits(int &); //declaration

```
int count_a(int);
```

};

int Solution::addDigits(int & num){

```
int temp=0,sum=0;
int count=count_a(num);
if(count<1)
return 0;
if(count==1){
return num;
}
else{
for(int i=0;i<count;i++){
temp=num%10; //remiander is saved in no
num=num/10;
sum+=temp;
}
}
do{
count=count_a(sum);
num=sum;
sum=0;
temp=0;
for(int i=0;i<count;i++){
temp=num%10; //remiander is saved in no
num=num/10;
sum+=temp;
}
}while(count>1);
return sum;
```

}

int Solution::count_a(int input){

```
int c=0;
do{
input=input/10;
c++;
}while(input!=0);
return c;
```

}

int main(){

```
Solution ob; //object of class is declared
int a,output;
cout<<"\nEnter the number:";
cin>>a;
output=ob.addDigits(a);
cout<<"\n the final required number is: "<<output;
return 0;
```

}