Wednesday, November 25, 2015

Consonants and Vowels Counter in C

A sample program that will ask the user to enter a work or a sentence and then the program will count how many consonants and vowels in a given word or sentence by the user. Take note I am using Turbo C 2.0 For DOS as my C compiler in this program.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output

Program Listing

/* Consonants and Vowels Counter               */
/* Written By: Mr. Jake R. Pomperada, MAED-IT  */
/* Date  : November 25, 2015                   */
/* Tools : Turbo C 2.0  For DOS                */

#include <stdio.h>
#include <ctype.h>
#include <conio.h>

  main()
    {
char strings[200];
int vowels=0,consonants=0,i=0;
clrscr();
printf("Enter a word or sentence : ");
gets(strings);

while(strings[i] != '\0')
{
if (toupper(strings[i])=='A' || toupper(strings[i])=='E' ||
toupper(strings[i])=='I' ||  toupper(strings[i])=='O'||
toupper(strings[i])=='U')

vowels++;



  if (toupper(strings[i])=='B' || toupper(strings[i])=='C' ||
toupper(strings[i])=='D' || toupper(strings[i])=='F'||
toupper(strings[i])=='G' || toupper(strings[i])=='H' ||
toupper(strings[i])=='J' || toupper(strings[i])=='K'||
toupper(strings[i])=='L' || toupper(strings[i])=='M' ||
toupper(strings[i])=='N' || toupper(strings[i])=='P'||
toupper(strings[i])=='Q' || toupper(strings[i])=='R' ||
toupper(strings[i])=='S' || toupper(strings[i])=='T'||
toupper(strings[i])=='V' || toupper(strings[i])=='W' ||
toupper(strings[i])=='X' || toupper(strings[i])=='Y' || 
                toupper(strings[i])=='Z')

consonants++;

i++;
}
printf("\n\n");
printf("===== DISPLAY RESULTS =====");
printf("\n\n");
printf("Total Number of Vowels     : %d. ", vowels);
printf("\n\n");
printf("Total Number of Consonants : %d.   ",consonants);
getch();
}



No comments:

Post a Comment