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
Does c++ have string data type?
Difference between pass by value and pass by reference?
What is a v-table?
Can you be able to identify between straight- through and cross- over cable wiring? And in what case do you use straight- through and cross-over?
How can I learn dev c++ programming?
Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300
What is the use of namespace std in C++?
What are the advantages of using a pointer? Define the operators that can be used with a pointer.
what are the iterator and generic algorithms.
What is rtti in c++?
When is the destructor called?
Explain what is polymorphism in c++?
What are c++ templates used for?
Explain the term memory alignment?
Define vptr.