C++ Program to Count Number of Digits in Given Number using While Loop
Write C++ Program to Count Number of Digits in Given Number using While Loop
// CPP Program to Count Number of Digits in Given Number using While Loop #include <iostream> using namespace std; int main() { long int n, m; int Count = 0; cout << "Enter the number :--> "; cin >> n; m = n; while(n > 0) { n = n / 10; Count = Count + 1; //count digits } cout << "Number of digits in " << m << " :--> " << Count; return 0; }
Output:
Enter the number :--> 654321
Number of digits in 654321 :--> 6