Header Ads Widget

Count number of digit in a number in C

 Count digit in a number in C

Given a number , write a program to count number of digits in a number . 

Sample input

78563

Sample output

5

 Count digit in a number in C

The objective of the code is to find the number of digits in a given number in c .

Code(C):-

#include<stdio.h>
int main()
{
int num,count=0;
printf("Enter a number\n");
scanf("%d",&num);
while(num!=0)
{
count+=1;
num/=10;
}
printf("Number of digits is %d",count);
return 0;
}

Output:-

Enter a number
78536
Number of digits is 5

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-