Pages

Friday, 11 August 2017

Vowel Count Switch statement

Q : using a switch statement, write a function to count the number of vowels and number of blanks
in a character array passed to it as an argument.

Solution 



#include<stdio.h>
#define MAX 20
void count(char*);

void main()
{
     char ch[MAX];
     printf("\n\tEnter String>> ");
     gets(ch);
     count(ch);
}
void count(char *str)
{
     int i,vowel=0,blank=0;
     for(i=0;str[i]!='\0';i++)
     {
           switch(str[i])
           {
                case 'a':
                case 'A':
                case 'e':
                case 'E':
                case 'i':
                case 'I':
                case 'o':
                case 'O':
                case 'u':
                case 'U':
                      vowel++;
                      break;
                case ' ':
                      blank++;
                      break;
           }
     }
     printf("\n\tVowel=%d\n\tBlank=%d",vowel,blank);
}

No comments:

Post a Comment