I have a string of alphabets and digits , in which i have to find the frequency of each digit from 0 to 9.
i have taken nested for loops , first for digits and second for string. then compare both with the use of if.. else..
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int i,j,count=0;
char s[1000];
scanf("%s",s);
for(i=0;i<=9;i++)
{
for(j=0;j<strlen(s);j++)
{
if(i==s[j])
{
count=count+1;
}
}
printf("%d ",count);
count=0;
}
return 0;
}
if input is 'abdf2343' then output must be 0 0 1 2 1 0 0 0 0 0. but my output is 0 0 0 0 0 0 0 0 0 0