+ 2

c code to find digit frequency?

Code to find digit frequency from the string which contains both characters and integers.

26th May 2019, 4:42 PM
Plp
6 Respuestas
+ 1
#include<stdio.h> #include<string.h> int main() { char str[1001]; scanf("%s", str) ; int lut[10]={0, }; for(int i=0;i<strlen(str);++i);{ if(str[i] >='0'&&str[i] <='9') { ++lut[str[i] - '0']; } } for(int i=0;i<10;++i) { printf("%d", lut[i]) ; } return 0; }
26th May 2019, 5:36 PM
Plp
+ 5
which language are you writing with??? I mean programing
26th May 2019, 5:25 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 4
Please show us your attempt.
26th May 2019, 4:49 PM
HonFu
HonFu - avatar
+ 3
you can link the code you have written, but it fails to work the way you want it, that might be good for a start
26th May 2019, 4:58 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 1
string is an array of characters, you can use a loop and to the freq. string s="uhdu-638-38-33"; int f3=0; for(int i=0; i<s.size(); i++) { if(s[i]=='3') f3++; }
26th May 2019, 5:09 PM
Farry
Farry - avatar
0
Use a search algorithm
26th May 2019, 5:39 PM
Werg Serium
Werg Serium - avatar