You are viewing a single comment's thread. Return to all comments →
//if you dont know much about pointer int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int a[10]={0,0,0,0,0,0,0,0,0}; char s; s = (char)malloc(1000*sizeof(char)); scanf("%s", s); while(*s != '\0'){ if(*s=='0') ++a[0]; if(*s=='1') ++a[1]; if(*s=='2') ++a[2]; if(*s=='3') ++a[3]; if(*s=='4') ++a[4]; if(*s=='5') ++a[5]; if(*s=='6') ++a[6]; if(*s=='7') ++a[7]; if(*s=='8') ++a[8]; if(*s=='9') ++a[9]; ++s; } for(int i=0;i<10;i++){ printf("%d ",a[i]); } 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 →
include
include
include
//if you dont know much about pointer int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int a[10]={0,0,0,0,0,0,0,0,0}; char s; s = (char)malloc(1000*sizeof(char)); scanf("%s", s); while(*s != '\0'){ if(*s=='0') ++a[0]; if(*s=='1') ++a[1]; if(*s=='2') ++a[2]; if(*s=='3') ++a[3]; if(*s=='4') ++a[4]; if(*s=='5') ++a[5]; if(*s=='6') ++a[6]; if(*s=='7') ++a[7]; if(*s=='8') ++a[8]; if(*s=='9') ++a[9]; ++s; } for(int i=0;i<10;i++){ printf("%d ",a[i]); } return 0; }