Answer to Question #291562 in C++ for Unnati

Question #291562

Write a program to obtain a number (N) from the user and display whether the is a one digit number , 2 digit number, 3 digit number Or more than 3 digit number

1
Expert's answer
2022-01-28T07:59:34-0500
#include <bits/stdc++.h>

using namespace std;

 

int countDigit(long long n) { 


  return floor(log10(n) + 1); 

}
 

int main(void)

{

    long long n;
    cout << "Enter an integer: ";
    cin >> n;

    cout << "Number of digits : "


         << countDigit(n);


    return 0;

}

Enter an integer: 23
Number of digits : 2

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog