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
Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.
What is friend class in c++ with example?
How is modularity introduced in C++?
What are the steps in the development cycle?
How do c++ struct differs from the c++ class?
Explain linked list using c++ with an example?
How is new() different from malloc()?
What is c++ 11 and c++ 14?
Write a note about the virtual member function?
what is the difference between overloading & overriding? give example.
. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?
What is the hardest coding language to learn?
Which of the following is evaluated first: a) && b) || c) !
What is atoi?
Can a program run without main in c++?