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
Difference between a homogeneous and a heterogeneous container
What is buffering in c++?
What is the iunknown interface?
Which bit wise operator is suitable for checking whether a particular bit is on or off?
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 What is singleton pattern in c++? Is it legal in c++ to overload operator++ so that it decrements a value in your class? What are the benefits of operator overloading? What is a memory leak c++? What are files in c++? What is the header file for setw? What is linked list in c++? Why is c++ still best? What do you mean by function and operator overloading in c++? What is meant by const_cast?