You are viewing a single comment's thread. Return to all comments →
using the ASCII value concept #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char* arr; arr = (char*)malloc(sizeof(char)*1001); int total = 0; scanf("%s",arr); arr = (char*)realloc(arr,sizeof(char)*(strlen(arr)+1)); int* countno; countno = (int*)calloc(sizeof(int),10); for(int i = 0;i < strlen(arr);i++){ ((int)arr[i] >47 && (int)arr[i] <58)?countno[(int)arr[i] - 48] += 1 :(countno[0] = countno[0]); } free(arr); arr = NULL; for(int i =0; i<10;i++){ printf("%d ",countno[i]); } free(countno); countno = NULL; return 0; }
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 →