To count number of digits | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

To count number of digits

Input : 789 Output : 3

5th Sep 2017, 3:26 PM
Harsh Tirkey
Harsh Tirkey - avatar
1 Answer
+ 4
#include <iostream> using namespace std; int main() { int x; int count=0; int d=10; cin>> x; do { if(x/d!=0) { count++; d*=10; } else { d=0; } }while(d!=0); cout << count+1 << endl; return 0; }
5th Sep 2017, 3:37 PM
Vahid
Vahid - avatar