Number of digits used in integer

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 ");
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
Your Rating

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 All rights reserved worldwide Privacy Policy Disclaimer