How many times to repeat?

i need help here is problem
The positive integer number N is given. We subtract from this number the sum of its digits. From the received number we soon subtract the sum of its digits and so on. This operation continues until the number is positive. How many times this operation will be repeated?
and here is my code what is wrong here?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cmath>

using namespace std;
int num,sumdgt=0,m=0,k;
void dgt(int);

int main(){using namespace std;
cin>>num;
do
{

     k=num-dgt(num);
     num=k;
     m++;}
   while(k>=0);
cout<<m<<endl;
return 0;
}
void dgt(int l){
    using namespace std;
 while (l > 0) {
     long digit = l % 10;
   sumdgt=sumdgt+digit;
        l /= 10;}
   }
Last edited on

The positive integer number N is given.
...explanation of operation
This operation continues until the number is positive.


Erm...it's already positive, so none? If you did it with a negative number it would never become positive it would keep getting smaller. I think you've made an error in describing what you want.
Last edited on
and here is my code what is wrong here?
It does not compile. And you've got an infinite loop.
Last edited on
actually i copy paste this problem what alghorithym can i use to solve this?
Topic archived. No new replies allowed.