Example on switch statement

Example on switch statement:
  /*To count the number of vowels in a given word.*/
#include<stdio.h>
main()
{
char word[80];
int i=0,ca,ce,ci,co,cu;
ca=ce=ci=co=cu=0;
printf("\nEnter any word ");
scanf("%s",word);

while(word[i]!='\0')
{
  switch(word[i])
  {
   case 'a':
   case 'A':  ca++;
                  break;

   case 'e':
   case 'E':  ce++;
                  break;

    case 'i':
    case 'I':  ci++;
                  break;

     case 'o':
     case 'O':  co++;
                  break;

     case 'u':
     case 'U':  cu++;
                  break;

     default: others++;
                 break;
   }
i++;
}
printf("\na=%d\ne=%d\ni=%d\no=%d\nu=%d",a,e,i,o,u);
}



Comments