diff --git a/integer.c b/integer.c new file mode 100644 index 0000000..92c5007 --- /dev/null +++ b/integer.c @@ -0,0 +1,17 @@ +#include +int main() { + long long n; + int count = 0; + printf("Enter an integer: "); + scanf("%lld", &n); + + // iterate at least once, then until n becomes 0 + // remove last digit from n in each iteration + // increase count by 1 in each iteration + do { + n /= 10; + ++count; + } while (n != 0); + + printf("Number of digits: %d", count); +}