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
What parameter does the constructor to an ofstream object take?
What is DlgProc?
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
Can you please explain the difference between using macro and inline functions?
Which bit wise operator is suitable for turning off a particular bit in a number?
What is a multiset c++?
Write a program using display() function which takes two arguments.
Differentiate between the manipulator and setf( ) function?
Explain register storage specifier.
What is ios flag in c++?
what are the events occur in intr activated on interrupt vector table
If a header file is included twice by mistake in the program, will it give any error?
Explain the difference between struct and class in terms of access modifier.
What is the C-style character string?
What does the nocreate and noreplace flag ensure when they are used for opening a file?