You are given a string S. Count the number of occurrences of all the digits in the string S.
Input: First line contains string S.
Output: For each digit starting from 0 to 9, print the count of their occurrences in the string S. So, print 10 lines, each line containing 2 space separated integers. First integer i and second integer count of occurrence of i. See sample output for clarification.
Constraints:1≤|S|≤100
I tried doing it this way. But I'm getting errors.
error: array subscript is not an integer. and error: invalid operands to binary.
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
double a[100],i,k;
int b[10]={0,1,2,3,4,5,6,7,8,9},sum[10];
int j;
gets(a);
k=strlen(a);
for(i=0; i<10; i++){
sum[i]=0;
}
for(i=0; i<k; i++){
a[i]=a/(pow(10,k-i-1));
for(j=0; j<k; j++){
if(i+j<10 && a[i]==a[i+j])
sum[i]++;
else
break;
}
}
printf("%d/n",b[i]);
puts(sum[i]);
return 0;
}
Please help.