Question #345275

Input a number and display that how many digits it has.


Expert's answer

#include <iostream>
using namespace std;
int main() {
    int n, amountDigits=1;
    cout<<"Enter a number: ";
    cin>>n;
    int temp = n;
    while(temp>9){
        amountDigits++;
        temp/=10;
    }
    cout<<amountDigits;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS