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

Difference between a homogeneous and a heterogeneous container

657


What is buffering in c++?

580


What is the iunknown interface?

674


Which bit wise operator is suitable for checking whether a particular bit is on or off?

601


how can i access a direct (absolute, not the offset) memory address? here is what i tried: wrote a program that ask's for an address from the user, creates a FAR pointer to that adress and shows it. then the user can increment/decrement the value in that address by pressing p(inc+) and m(dec-). NOW, i compiled that program and opened it twice (in 2 different windows) and gave twice the same address to it. now look what happen - if i change the value in one "window" of the program, it DOES NOT change in the other! even if they point to the same address in the memory! here is the code snippet: //------------------------------------------------------ #include //INCLUDE EVERY KNOWN HEADER FILE #include //FOR ANY CASE... #include #include #include main() { int far *ptr; //FAR POINTER!!! long address; char key=0; //A KEY FROM THE KEYBOARD int temp=0; clrscr(); cout<<"Enter Address:"; cin>>hex>>address; //GETS THE ADDRESS clrscr(); (long)ptr=address; temp=*ptr; //PUTS THE ADDRESS IN THE PTR cout<<"["<

1810






What is singleton pattern in c++?

544


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

606


What are the benefits of operator overloading?

675


What is a memory leak c++?

585


What are files in c++?

587


What is the header file for setw?

571


What is linked list in c++?

689


Why is c++ still best?

547


What do you mean by function and operator overloading in c++?

606


What is meant by const_cast?

643