Pages

  • Home
  • About & Contact
  • Archive
  • C Programming Examples

20 March 2012

c program to count the number of vowels and consonants in a string

Here is the program to count number of vowels and consonants in c.
vowels and consonants

#include<stdio.h>
//#include<conio.h>
#include<string.h>
void main()
{
    char str[50];
    int vovels=0,consonants=0,len,i;
    printf("Enter the String:\n");
    gets(str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
           if((str[i]>64&&str[i]<91)||(str[i]>96&&str[i]<123))             //Firstly checking the character is alphabet or not
{
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U')              //checking if it is vowel or not
 vovels++;
     else
 consonants++;
}
    }
    printf("Number of vovels = %d and consonants = %d ",vovels,consonants);
   //getch();
}

Similar programs:

c program to count number of words,spaces,characters,digits and special symbols

2 comments:

  1. simple and good

    ReplyDelete
  2. Anonymous12 June, 2013

    This comment has been removed by a blog administrator.

    ReplyDelete