#include <stdio.h>
int main()
{
long long num, n;
int i, lastDigit;
int freq[10];
/* Input number from user */
printf("Enter any number: ");
scanf("%lld", &num);
for (i = 0; i < 10; i++)
{
freq[i] = 0;
}
n = num;
while (n != 0)
{
lastDigit = n % 10;/// for getting the last digit of the number
n /= 10; /// for removing the last digit of the number
freq[lastDigit]++;
}
printf("Frequency of each digit in %lld is: \n", num);
for (i = 0; i < 10; i++)
{
printf("Frequency of %d = %d\n", i, freq[i]);
}
return 0;
}
Output:-
Enter any number : 165464536546
Frequency of each digit in 165464536546 is :
Frequency of 0 = 0
Frequency of 1 = 1
Frequency of 2 = 0
Frequency of 3 = 1
Frequency of 4 = 3
Frequency of 5 = 3
Frequency of 6 = 4
Frequency of 7 = 0
Frequency of 8 = 0
Frequency of 9 = 0
0 Comments