int countDigitOne(int n) {

```
if(n<=0){
return 0;
}
int count = 0;
int rmd = 0;
int divd = 0;
for(int m=1; m<=n; m++){
rmd = m%10;
divd = m/10;
if(rmd == 1){
count++;
}
if(divd == 1){
count++;
}
while(divd > 9){
rmd = divd%10;
divd = divd/10;
if(rmd == 1){
count++;
rmd = 0;
}
if(divd == 1){
count++;
}
}
}
return count;
```

}