Write a program to find the frequency of characters in a string(case insensitivity).
| Solution in | C | JAVA | PYTHON |
|---|
#include<stdio.h>
#include<string.h>
int main(){
char s[50];
gets(s);
strlwr(s);
for(int i=0;i<strlen(s);i++){
int count=1;
int flag=0;
for(int j=0;j<i;j++){
if(s[i]==s[j]){
flag=1;
break;
}
}
if(flag==1){
continue;
}
for(int j=i+1;j<strlen(s);j++){
if(s[i]==s[j]){
count++;
}
}
printf("%c - %d\n",s[i],count);
}
return 0;
}
#include<string.h>
int main(){
char s[50];
gets(s);
strlwr(s);
for(int i=0;i<strlen(s);i++){
int count=1;
int flag=0;
for(int j=0;j<i;j++){
if(s[i]==s[j]){
flag=1;
break;
}
}
if(flag==1){
continue;
}
for(int j=i+1;j<strlen(s);j++){
if(s[i]==s[j]){
count++;
}
}
printf("%c - %d\n",s[i],count);
}
return 0;
}
helloHowarEyou?
h - 2
e - 2
l - 2
o - 3
w - 1
a - 1
r - 1
y - 1
u - 1
? - 1