C - Program to count number of Vowels in a string using Pointers.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char st[100], *sptr;
int count = 0;
printf("\n Enter the String: \n");
gets(st);
sptr = st;
/* loop to count vowels */
while(*sptr != '\0')
{
switch(*sptr)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u': count++;
break;
}
sptr++;
}
printf("\n Number of vowel = %d \n\n",count);
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char st[100], *sptr;
int count = 0;
printf("\n Enter the String: \n");
gets(st);
sptr = st;
/* loop to count vowels */
while(*sptr != '\0')
{
switch(*sptr)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u': count++;
break;
}
sptr++;
}
printf("\n Number of vowel = %d \n\n",count);
}
OUTPUT:
0 Comments