Count Digits Method-1¶ C++ countDigits.cpp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18#include <bits/stdc++.h> using namespace std; int countDigits(int n){ int count = 0; while(n > 0) { n /= 10; count++; } return count; } int main() { int n; cin >> n; cout << countDigits(n); return 0; } Input: 5432 Output: 4 Method-2¶ C++ countDigits.cpp 1 2 3 4 5 6 7 8 9 10 11 12 13 14#include <bits/stdc++.h> using namespace std; int countDigits(int n){ int count = floor(log10(n) + 1); return count; } int main() { int n; cin >> n; cout << countDigits(n); return 0; } Input: 5432 Output: 4