Write a program that will count the number of digits in an
input integer up to value MAX_VALUE (2147483647). Thus, for
an input of 5837 the output should be
4 digits
Make sure that your program works for the numbers 0, 1, and
10. For the number 0, the output should be
1 digit
Answer Posted / sandeep mannarakkal
I have another suggestion for the above,
int iInputNumber;// This number is used for collecting input from user.
int nCount = 1;
while ( iInputNumber /10 )
{
iInputNumber = iInputNumber/10;
nCount ++;
}
cout << nCount << endl; // nCount will have the count of digits.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is c++ good for?
Explain how to initialize a const data member.
What is the size of a vector?
What is flush c++?
What is pair in c++?
why and when we can declar member fuction as a private in the class?
Why are arrays usually processed with for loop?
What is the difference between structure and class?
What is the difference between method overloading and method overriding in c++?
What is ofstream c++?
Will the following program execute?
Explain the different access specifiers for the class member in c++.
How do you define/declare constants in c++?
Explain about vectors in c ++?
Mention the purpose of istream class?