Write a C++ program to find the number of vowels present in the given character array using pointer arithmetic.

Implementation of the above problem:
#include<iostream.h>
void main()
{
const int nArraySize=20;
char szName[nArraySize];
cout<<"\nEnther the word:";
cin>>szName;
int nVowels = 0;
for (char *pnPtr = szName; pnPtr <= szName + nArraySize; pnPtr++)
{
switch (*pnPtr)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
nVowels++;
break;
}
}
cout << szName << " has " << nVowels << " vowels" << endl;
}


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: