given an input string Ayodhya your C program to count the number of vowels and consonants and print the frequency of occurrence of each vowel and consonant delete the vowels in the same input string and display the updated string
Sample input:
Enter the input string: Ayodhya
Sample output:
No of vowels:3
Frequency of occurrence:A-2;o-1
No of consonants:4
Frequency of occurrence:y-2;d-1;h-1
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define N_VOWEL 5
#define N_CONS 21
#define BUF_SIZE 80
int main() {
char vowel[N_VOWEL] = "aeiou";
int vCount[N_VOWEL] = {0};
int vTot = 0;
char cons[N_CONS] = "bcdfghjklmnpqrstvwxyz";
int cCount[N_CONS] = {0};
int cTot = 0;
int i, j, done;
char buf[BUF_SIZE];
char ch;
gets(&buf);
for (i=0; i<strlen(buf); i++) {
ch = tolower(buf[i]);
done = 0;
for (j=0; j<N_VOWEL; j++) {
if (ch == vowel[j]) {
vCount[j]++;
vTot++;
done = 1;
break;
}
}
if (done) {
continue;
}
for (j=0; j<N_CONS; j++) {
if (ch == cons[j]) {
cCount[j]++;
cTot++;
break;
}
}
}
printf("No of vowels: %d\n", vTot);
printf("Frequency of occurrence: ");
for (j=0; j<N_VOWEL; j++) {
if (vCount[j] > 0) {
printf("%c - %d; ", vowel[j], vCount[j]);
}
}
printf("\n");
printf("No of Cconsonants: %d\n", cTot);
printf("Frequency of occurrence: ");
for (j=0; j<N_CONS; j++) {
if (cCount[j] > 0) {
printf("%c - %d; ", cons[j], cCount[j]);
}
}
printf("\n");
return 0;
}
Comments
Leave a comment