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

What is the use of register keyword with the variables?

636


what are the iterator and generic algorithms.

1788


What do you understand by pure virtual function? Write about its use?

671


Can we distribute function templates and class templates in object libraries?

674


Keyword mean in declaration?

678






What is difference between c++ 11 and c++ 14?

661


What are the five basic elements of a c++ program?

692


Write a program to read the data and evaluate the results of the election. Print all output to the screen. Your output should specify: The total number of votes, the number of valid votes and the number of spoilt votes. The winner(s) of the election. Hint: An appropriate search should be used to determine the winner(s). The votes obtained by each candidate sorted in terms of the number of votes obtained. Hint: An appropriate sort should be used to sort the candidate(s). The Source code should be saved as VotingSystem. Project Input: Candidates’ Names and Numbers 2501 Victor Taylor 2502 Denise Duncan 2503 Kamal Ramdhan 2504 Michael Ali 2505 Anisa Sawh 2506 Carol Khan 2507 Gary Owen Votes 3 1 2 5 4 3 5 3 5 3 2 8 1 6 7 7 3 5 6 9 3 4 7 1 2 4 5 5 1 4 0 Project Output: Invalid vote: 8 Invalid vote: 9 Number of voters: 30 Number of valid votes: 28 Number of spoilt votes: 2 The winner(s): 2503 Kamal Ramdhan 2505 Anisa Sawh Candidate Score 2503 Kamal Ramdhan 6 2505 Anisa Sawh 6 2501 Victor Taylor 4 2504 Michael Ali 4 2502 Denise Duncan 3 2507 Gary Owen 3 2506 Carol Khan 2

2751


Can char be a number c++?

685


What does std :: flush do?

783


Write about the scope resolution operator?

690


Mention the storage classes in c++.

739


What is abstract keyword in c++?

709


what is the use of void main() in C++ language?

760


What does flush do?

653