Count frequency of digits in an integer
C program to count frequency of digits in an integer.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
long long num;
int last_digit;
int i, freq[10];
printf("Enter the number\t:");
scanf("%lld",&num);
for(i=0; i<10; i++)
{
freq[i] = 0;
}
while(num>0)
{
last_digit = num % 10;
num = num / 10;
freq[last_digit]++;
}
for(i=0;i<10;i++)
{
printf("\nFrequency of %d = %d",i,freq[i]);
}
getch();
}
Output
Enter the number :114220569800
Frequency of 0 = 3
Frequency of 1 = 2
Frequency of 2 = 2
Frequency of 3 = 0
Frequency of 4 = 1
Frequency of 5 = 1
Frequency of 6 = 1
Frequency of 7 = 0
Frequency of 8 = 1
Frequency of 9 = 1