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


Please Help Members By Posting Answers For Below Questions

Does c++ have string data type?

914


Difference between pass by value and pass by reference?

892


What is a v-table?

917


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?

868


How can I learn dev c++ programming?

818


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

2029


What is the use of namespace std in C++?

857


What are the advantages of using a pointer? Define the operators that can be used with a pointer.

852


what are the iterator and generic algorithms.

1719


What is rtti in c++?

897


When is the destructor called?

830


Explain what is polymorphism in c++?

899


What are c++ templates used for?

921


Explain the term memory alignment?

947


Define vptr.

804