Write a C Program to count numbers of vowels and consonants?
C

Write a C Program to count numbers of vowels and consonants?

Write a C Program to count numbers of vowels and consonants?

In the C Program to count numbers of vowels and consonants, we should use string, switch case for, etc., conditional statements and loops. You can see here how we can write a c program to count numbers of vowels and consonants. The letters of the alphabet that we normally associate as being the vowel letters are a, e, i, o, and u.

The letters of the alphabet that usually represent the consonant sounds are b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y, z.

 

/* to count no. of vowels and consonants */
#include<stdio.h>
#include<conio.h>
void main()
{
char str[20];
int i, cons, vow;
i=cons=vow=0;
clrscr();
printf("\nEnter a string: ");
gets(str);
for(i=0; str[i] != '\0'; i++)
{
if(str[i] !=' '&& str[i] != '\t')
switch(str[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': vow++;
break;
default : cons++;
}
}
printf("\n Number of vowels = %d", vow);
printf("\n Number of consonants = %d", cons);
}


run
Enter a string: parrot
Number of vowels = 2
Number of consonants = 4

——————————–

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.