Question: Write a program to find the frequency of Characters in a given String
Example: If the given String is: Vyom Labs Interview Preparation and we need to find the frequency of a in the string then the frequency of a will be 3.
Test case:
Input1: Tutorial Diary
Input 2: a
Output: The number of a in the Tutorial Diary string is 2
Solution: C program
// A c program based on string
//Important for Vyom labs Coding question for Vyom labs Interview Preparation
// A C program to find the Frequency of Characters
#include <stdio.h>
int main(void) {
char ch1[100], ch2;
int i, count=0;
printf("Enter your string \n");
gets(ch1);
printf("Enter the character which you want frequency of: \n");
scanf("%c", &ch2);
for(i=0;ch1[i]!='\0';++i) {
if(ch1[i]==ch2)
++count;
}
printf("The number of %c in the %s string is %d", ch2, ch1, count );
return 0;
}
Example: If the given String is: Vyom Labs Interview Preparation and we need to find the frequency of a in the string then the frequency of a will be 3.
Test case:
Input1: Tutorial Diary
Input 2: a
Output: The number of a in the Tutorial Diary string is 2
Solution: C program
// A c program based on string
//Important for Vyom labs Coding question for Vyom labs Interview Preparation
// A C program to find the Frequency of Characters
#include <stdio.h>
int main(void) {
char ch1[100], ch2;
int i, count=0;
printf("Enter your string \n");
gets(ch1);
printf("Enter the character which you want frequency of: \n");
scanf("%c", &ch2);
for(i=0;ch1[i]!='\0';++i) {
if(ch1[i]==ch2)
++count;
}
printf("The number of %c in the %s string is %d", ch2, ch1, count );
return 0;
}