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

Differentiate between a constructor and a method in C++.

700


What are the various access specifiers in c++?

740


Why cout is used in c++?

721


How do we balance an AVL Tree in C++?

806


What do you mean by function pointer?

776






what are the iterator and generic algorithms.

1627


What is the difference between public, private, and protected access?

752


Should a constructor be public or private?

698


State the difference between pre and post increment/decrement operations.

759


Is set c++?

716


What are static type checking?

764


Do you know what is overriding?

741


How do we implement inheritance in c++?

761


what is pre-processor in C++?

739


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

2151