Search This Blog

Tuesday, 25 February 2014

counting number of vowels in a string in C++

program for checking number of vowels in a string

/*
  as we know that there is 5 vowels in our english alphabets.
  such as "a,e,i,o,u";
*/


#include<iostream.h>
#include<conio.h>
 int main()
  {
   char ch[25];
   int i,l=0;
   cout<<"Enter a string:\n";
   cin.getline(ch,25);
   for(i=0;ch[i]!='\0';i++)
   {
     //checking conditions for lower case only u can also implement for uppercase letters
     if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u')
     {
       l++;
       cout<<"\nvowel is : "<<ch[i]<<" and its position is at : "<<i+1;
      }
   }
   cout<<"\n\nNumber of vowels are in the string is : "<<l;
   getch();
  }

Output


No comments:

Popular Posts