C program to count the number of vowels in string: To calculate a total number of vowels present in the string.

What are the vowels?
In alphabets, as we know there are total 5 vowels A, E, I, O, U and remaining are the consonant.

Algorithm to count the number of vowels in a string

  1. Define Counter. Cnt=0
  2. Take the input string from the user.
  3. Traverse the string from start to end one by one character
    If character == Vowel
    Increment counter variable. Cnt++
    If String reaches the end
    Break
  4. If cnt == 0
    Print No vowels in the string
    else
    Print counter value as number of vowels present in string.

C program to count the number of vowels in string

#include <stdio.h>
#include<conio.h>
void main ()
{
//declare variables
char s [10];
int i , cnt;
// take input string
printf ("Enter string ");
scanf ("%s",&s);
// check for vowel
for (i=0; s [i] != '
#include <stdio.h>
#include<conio.h>
void main ()
{
//declare variables
char s [10];
int i , cnt;
// take input string
printf ("Enter string ");
scanf ("%s",&s);
// check for vowel
for (i=0; s [i] != '\0'; i++ )
{
if (s [i] == 'A' || s [i] == 'a' || s [i] =='e' || s [i] =='E' || s [i] =='i' || s [i] =='I' || s [i] =='o' || s [i]=='O' || s [i] =='u' || s [i] =='U')
{
cnt ++;
}
}
if (cnt == 0)
{
printf ("\n No vowels in string ");
}
else {
printf ("\n Number of vowels in %s is %d",s,cnt);
}
}
'; i++ ) { if (s [i] == 'A' || s [i] == 'a' || s [i] =='e' || s [i] =='E' || s [i] =='i' || s [i] =='I' || s [i] =='o' || s [i]=='O' || s [i] =='u' || s [i] =='U') { cnt ++; } } if (cnt == 0) { printf ("\n No vowels in string "); } else { printf ("\n Number of vowels in %s is %d",s,cnt); } }

Output :

C program to count the number of vowels in string

Write A Comment