Author Topic: Turbo C Program for displaying number of consonants in a statement  (Read 1086 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
I have given here a Turbo C Program for displaying number of consonants in a statement:


Code:
//Source Code Listing


#include <stdio.h>
#include <string.h>

void main()
{
   int i, j, len;
   int count = 0;
   int isVowel = 0;
   char buffer[512];
   static char v[] = { 'a', 'e', 'i', 'o', 'u',
                       'A', 'E', 'I', 'O', 'U',
                     };
   printf("Enter a String: ");
   gets(buffer);

   len = strlen(buffer);

   for(i = 0; i < len; i++)
   {
      isVowel = 0;
      for(j = 0; j < sizeof(v) / sizeof(v[0]); j++)
      {
         if(buffer[i] == v[j])
         {
            isVowel = 1;
            break;
         }
      }
      if(isVowel == 0)
         count++;
   }
   printf("\nNumber of consonants in the given string is: %d", count);
   getch();
   return;
   
}


output:
Enter a string: www.softwareandfinance.com
Number of consonants in the given string is: 18

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1