Computer Science, asked by vasavikarakavalasa20, 1 month ago

// you can print the values to stdout for debugging int count digits (int num) { int count =o, t=num; while ( num! =0) { num =num/10; count ++; } return (t% count) ;}​

Answers

Answered by sumitsihngnegi87
2

Answer:

The integer entered by the user is stored in the variable n. Then the while loop is iterated until the test expression n != 0 is evaluated to 0 (false). 

After the first iteration, the value of n will be 345 and the count is incremented to 1.

After the second iteration, the value of n will be 34 and the count is incremented to 2.

After the third iteration, the value of n will be 3 and the count is incremented to 3.

At the start of the fourth iteration, the value of n will be 0 and the loop is terminated.

Then the test expression is evaluated for false and the loop terminates. 

C++

// Iterative C++ program to count

// number of digits in a number

#include <bits/stdc++.h>

using namespace std;

 

int countDigit(long long n)

{

    int count = 0;

    while (n != 0)

    {

        n = n / 10;

        ++count;

    }

    return count;

}

Similar questions