Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,039 questions

52,004 answers

573 users

How to calculate frequency of vowels in a string in C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{
    int a = 0, e = 0, i = 0, o = 0, u = 0;
    char ch;

    printf("Type a string (Enter + Ctrl-c to exit): ");

    while ((ch = getchar()) != EOF) {
        if (ch == 'a' || ch == 'A')
            a++;
        if (ch == 'e' || ch == 'E')
            e++;
        if (ch == 'i' || ch == 'I')
            i++;
        if (ch == 'o' || ch == 'O')
            o++;
        if (ch == 'u' || ch == 'U')
            u++;
    }

    printf("Frequency of vowel 'a': %d\n", a);
    printf("Frequency of vowel 'e': %d\n", e);
    printf("Frequency of vowel 'i': %d\n", i);
    printf("Frequency of vowel 'o': %d\n", o);
    printf("Frequency of vowel 'u': %d\n", u);

    return 0;
}


/*
run:

Type a string (Enter + Ctrl-c to exit): abvciiooohgdueeee
Frequency of vowel 'a': 1
Frequency of vowel 'e': 4
Frequency of vowel 'i': 2
Frequency of vowel 'o': 3
Frequency of vowel 'u': 1

*/

 



answered Nov 4, 2016 by avibootz
edited Jul 17, 2024 by avibootz

Related questions

1 answer 118 views
1 answer 106 views
106 views asked Mar 27, 2022 by avibootz
2 answers 149 views
1 answer 82 views
1 answer 83 views
1 answer 98 views
1 answer 114 views
...