We can find out number of digits used in a number by using strlen string function. Before that we have to convert the number into string by strintf . Here is the sample code to display number of digits used.
#include <stdio.h>
#include <string.h>
int main(void){
char var[20];
int num;
printf("Enter a number ");
scanf("%d",&num);
sprintf(var,"%d", num);
printf(" number of digits = %d", strlen(var));
return 0;
}
If you input 2341 the output will be 4
for 0342 the output will be 3