To count the number of digits in an integer
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, count = 0;
clrscr();
printf("Enter a number : ");
scanf("%d", &n);
while(n > 0)
{
count++;
n = n / 10;
}
printf("\nThe number of digits is : %d", count);
getch();
}
Output:
Enter a number : 179
The number of digits is : 3
-
UpdatedDec 30, 2019
-
Views5,828
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order