Counting digits using while loop

前端 未结 7 548
清酒与你
清酒与你 2021-01-05 10:15

I was recently making a program which needed to check the number of digits in a number inputted by the user. As a result I made the following code:

int x;            


        
相关标签:
7条回答
  • 2021-01-05 10:41
    #include<iostream>
    using namespace std;
    int main()
    {
    int count=0;
        double x;
        cout << "Enter a number: ";
        cin >> x;
        x /= 10;
        while(x > 1)
        {
          count++;
          x = x/10;
        }
        cout<<count+1;
    }
    
    0 讨论(0)
提交回复
热议问题