# AMCAT Coding Questions asked in Programming Section Count Frequency of digits

### Program to count frequency of digits in an integer

`/**`
` ``* C program to count frequency of digits in a given number`
` ``*/`

`#include <stdio.h>`
`#define BASE 10`

`int` `main()`
`{`
`    ``long` `long` `num, n;`
`    ``int` `i, lastDigit;`
`    ``int` `freq[BASE];`

`    ``printf``(``"Enter any number: "``);`
`    ``scanf``(``"%lld"``, &num);`

`    ``// Initializes frequency array with 0`
`    ``for``(i=0; i<BASE; i++)`
`    ``{`
`        ``freq[i] = 0;`
`    ``}`

`    ``n = num; ``//Copies the value of num to n`

`    ``while``(n != 0)`
`    ``{`
`        ``// Gets the last digit`
`        ``lastDigit = n % 10;`

`        ``// Increments the frequency array`
`        ``freq[lastDigit]++;`

`        ``// Removes the last digit from n`
`        ``n /= 10;`
`    ``}`

`    ``printf``(``"Frequency of each digit in %lld is: \n"``, num);`
`    ``for``(i=0; i<BASE; i++)`
`    ``{`
`        ``printf``(``"Frequency of %d = %d\n"``, i, freq[i]);`
`    ``}`

`    ``return` `0;`
`}`

```  Output Enter any number: 11203458760011Frequency of each digit in 11203458760011 is:Frequency of 0 = 3Frequency of 1 = 4Frequency of 2 = 1Frequency of 3 = 1Frequency of 4 = 1Frequency of 5 = 1Frequency of 6 = 1Frequency of 7 = 1Frequency of 8 = 1Frequency of 9 = 0 ```