Write a C++ program to count number of digits in a number n which will be input by the user.
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Please, enter a number n: ";
cin >> n;
int i = 0;
while (n > 0)
{
n /= 10;
i++;
}
cout << "Number of digits in n is " << i;
}
Comments
Leave a comment