C Programming Code Examples C > For Loops and While Loops Code Examples Program to count number of digits without using loop Program to count number of digits without using loop Logic to count number of digits without using loop The second logic uses logarithms to count number of digits in a given integer. Total number of digit in a given integer is equal to log10(j) + 1. Where log10() is a predefined function present in math.h header file. It returns logarithm of parameter passed to the base 10. However, you can use it to count total digits using formula log10(j) + 1. /* C program to count number of digits in an integer without loop */ #include <stdio.h> #include <math.h> /* Used for log10() */ int main() { long long j; int count = 0; /* Input number from user */ printf("Enter any number: "); scanf("%lld", &j); /* Calculate total digits */ count = log10(j) + 1; printf("Total digits: %d", count); return 0; }