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

If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

1263


What is the meaning of string in c++?

802


How do you flush a buffer in c++?

812


Where and why do I have to put the "template" and "typename" keywords?

797


List the issue that the auto_ptr object handles?

822


What is basic if statement syntax?

785


By using c++ with an example describe linked list?

807


What do you mean by translation unit in c++?

974


Is it possible to use a new for the reallocation of pointers ?

814


Why use of template is better than a base class?

875


What are c++ data types?

891


what is scupper?

2095


Write a program in C++ for Fibonacci series

881


What causes a runtime error c++?

836


What's the best free c++ profiler for windows?

845