Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Count Number of Vowels

C++ Program To count the number of Vowels in given string. This program calculates the number of vowels in a string using for loop. The string is input by the user using gets(). Using gets() allows the compiler to input the spaces of string also. We have taken a variable count whose value increases by 1 when a vowel in encountered during the scan. So value of count keeps on increasing
until the string scan is completed and vowels are encountered.The length of string is calculated and the result is  printed on compiler screen.
Source Code:-

#include<iostream.h>
#include<conio.h>

void main()
{
 char ch[20];
 int i,count=0;
 clrscr();
 cout<<"Prgram to count number of vowels by-Tarun Rawat\n";
 cout<<"Enter the string\n";
 gets(ch);
 for(i=0;ch[i]!='\0';i++)
 {
  if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' || ch[i]=='o' ||
   ch[i]=='u')
  {
   count++;
  }
 }
 cout<<"Vowels = "<<count;
 getch();
}

No comments:

Post a Comment

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)