Counting digits using while loop

前端 未结 7 615
清酒与你
清酒与你 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条回答
  •  猫巷女王i
    2021-01-05 10:41

    #include
    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<

提交回复
热议问题