Print vowels,consonent,captital,small and special character using String in C


This program is about checking and print the number of vowel, consonent,capital,small and special characters in the given string using for loop and if conditions.

Source Code

#include<stdio.h>
int main()
{
  int i,small=0,cap=0,vowel=0,cons=0,spl=0;
  char a[100];
  printf("\nEnter the Sentence:");
  gets(a);
  for(i=0;a[i]!='\0';i++)
  {
    if(a[i]>=97&&a[i]<=122)
    {
        small++;
        if(a[i]==97||a[i]==101||a[i]==105||a[i]==111||a[i]==117)
        {
            vowel++;
        }
        else
        {
            cons++;
        }
    }
    else if(a[i]>=65&&a[i]<=90)
    {
      cap++;
	  
      if(a[i]==65||a[i]==69||a[i]==73||a[i]==79||a[i]==85)
      {
        vowel++;
      }
      else
      {
        cons++;
      }
    }
    else
    {
       spl++;
    }
  }

  printf("\nVowels:%d",vowel);
  printf("\nConsonents:%d",cons);
  printf("\nCapital letters:%d",cap);
  printf("\nSmall letters:%d",small);
  printf("\nSpecial characters:%d",spl);
  return 0;
}
To download raw file Click Here

Output

Enter the Sentence: Tutor Joe's Computer Education is the best education center
Tutor Joe's Computer Education is the best education center

Vowels:22
Consonents:28
Capital letters:4
Small letters:46
Special characters:9

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes