We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int main() {
char str[1000];
int digit_count[10] = {0};
// Input string
printf("Enter a string: ");
scanf("%s", str);
// Iterate through the characters of the input string
for (int i = 0; i < strlen(str); i++) {
if (str[i] >= '0' && str[i] <= '9') {
int digit = str[i] - '0';
digit_count[digit]++;
}
}
// Print the frequency of each digit
printf("Frequency of each digit from 0 to 9: ");
for (int i = 0; i < 10; i++) {
printf("%d ", digit_count[i]);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Digit Frequency
You are viewing a single comment's thread. Return to all comments →
include
int main() { char str[1000]; int digit_count[10] = {0};