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 is flush programming?

797


What is #include math h in c++?

820


Which should be more useful: the protected and public virtuals?

805


What is object in c++ wikipedia?

782


write a porgram in c++ that reads an integer and print the biggest digit in the number

2045


Why do we learn c++?

751


Why null pointer is used?

810


Give an example of run-time polymorphism/virtual functions.

789


What is a node class in c++?

855


What is a namespace in c++?

1494


Can you be able to identify between straight- through and cross- over cable wiring? And in what case do you use straight- through and cross-over?

868


Can I make ios apps with c++?

795


What is anonymous object in c++?

875


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

800


Where the memory to the static variables is allocated?

818