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 / usama azam

#include<iostream.h>
int main ()
{
int num;
cout<<"enter the number ";
cin>>num;
if (num>=0 && num<=9)
cout<<"You have entered one digit";
else if (num>=10 && num<=99)
cout<<"You have entered two digits";

else if (num>=100 && num<=999)
cout<<"You have entered three digits";


else if (num>=1000 && num<=9999)
cout<<"You have entered four digits";

else if (num>=10000 && num<=99999)
cout<<"You have entered five digits";


else if (num>=100000 && num<=999999)
cout<<"You have entered six digits";

else if (num>=1000000 || num<=9999999)
cout<<"You have entered seven digits";
system("pause");
return 0;

}

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What parameter does the constructor to an ofstream object take?

703


What is DlgProc?

682


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

2747


Can you please explain the difference between using macro and inline functions?

620


Which bit wise operator is suitable for turning off a particular bit in a number?

733






What is a multiset c++?

664


Write a program using display() function which takes two arguments.

700


Differentiate between the manipulator and setf( ) function?

700


Explain register storage specifier.

689


What is ios flag in c++?

769


what are the events occur in intr activated on interrupt vector table

1261


If a header file is included twice by mistake in the program, will it give any error?

645


Explain the difference between struct and class in terms of access modifier.

799


What is the C-style character string?

698


What does the nocreate and noreplace flag ensure when they are used for opening a file?

759