Given a string, s, consisting of alphabets and digits, find the frequency of each digit in the given string
Answers
Answered by
0
Answerjh
Explanation:
jh
Answered by
0
Answer:
//Digit Frequency in C - Hacker Rank Solution
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *s;
s = malloc(1024 * sizeof(char));
scanf("%s", s);
s = realloc(s, strlen(s) + 1);
int len = strlen(s), i;
int arr[10];
for(i = 0; i < 10; i++)
arr[i] = 0;
for(i = 0; i < len; i++) {
if(s[i] >= '0' && s[i] <= '9') {
arr[(int)(s[i] - '0')]++;
}
}
for(i = 0; i < 10; i++)
printf("%d ", arr[i]);
printf("\n");
free(s);
return 0;
}
Similar questions
Social Sciences,
18 days ago
History,
18 days ago
Business Studies,
18 days ago
Chemistry,
1 month ago
Biology,
1 month ago
Math,
9 months ago
English,
9 months ago