Computer Science, asked by abcxyz7869210, 1 month ago

wap to accept a number and display whether it is a single digit , double digit or multi digit in c++


its urgent ​

Attachments:

Answers

Answered by anindyaadhikari13
5

\texttt{\textsf{\large{\underline{Solution}:}}}

The given problem is solved using language - C++.

#include <iostream>

using namespace std;

int main() {

   int n,c=0;

   cout<<"Enter a number: ";

   cin>>n;

   while(n!=0){

       c++;

       n/=10;

   }

   if(c==1)

       cout<<"Its a single digit number.";

   else if(c==2)

       cout<<"Its a double digit number.";

   else

       cout<<"Its a multi digit number.";

   return 0;

}

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • Here, we have asked the user to enter a number.
  • The while loop counts the number of digits present in the number and store it in variable - 'c'.
  • After termination of while loop, if the value of c is '1', then a message is displayed that - "Number is single digit.".
  • If the value of c is 2, "Number is double digit" or else, it is "Multi Digit".

See attachment for output.

Attachments:
Similar questions