pTutorial

New way to learn C programming

C Program to check vowel

In this section, you can see a lot of vowel example like check the number of vowel, count the number of vowel and print all the vowel.

Example of check character

#include <stdio.h>
#include <conio.h>
void main()
{
   char a[20];
   int i,c=0;


   printf(" Enter the string: ");
   scanf("%s",a);
   for(i=0;i<strlen(a);i++)
   {

       if(a[i]=='A')
        {
           printf("%c ",a[i]);
           c=1;
        }
        else if(a[i]=='a')
       {
         printf("%c ",a[i]);
           c=1;
       }
       else if(a[i]=='E')
       {
         printf("%c ",a[i]);
           c=1;
       }
       else if(a[i]=='e')
       {
         printf("%c ",a[i]);
           c=1;
       }

       else if(a[i]=='I')
       {
           printf("%c ",a[i]);
           c=1;
       }
       else if(a[i]=='i')
       {
         printf("%c ",a[i]);
           c=1;
       }
       else if(a[i]=='O')
       {
           printf("%c ",a[i]);
           c=1;
       }
        else if(a[i]=='o')
       {
         printf("%c ",a[i]);
           c=1;
       }
       else if(a[i]=='U')
       {
           printf("%c ",a[i]);
           c=1;
       }
       else if(a[i]=='u')
       {
         printf("%c ",a[i]);
           c=1;
       }
    
}

      if(c==1)
       printf(" Vowels\n");
       else
       printf("Vowels is Not present");


}

Download C Vowel Program

In this program, we have initialized a character type array "char[a]" with the size of 20. "char[a]" will store string(which is given by user). strlen() is inbuilt function of .its calculate the length of string.

We have initialized a for loop which is start from zero to total length of string. As we know that a,e,i,o,u are vowels but in c language is case sensitive that means A, E, I, O, U and a, e, i, o, u are differ.

We check at the first position of string i.e a[0], if there is a vowel then print it and increase the value of i and again it will check the second position i.e a[1],check the vowel and print it and so on until total length of string and exit from for loop.

Finally if there are vowels then execute the (outer from for loop) if condition otherwise else.

Output of program

Check vowel | ptutorial

C program to check entered character is vowel or not.

//Check entered character is vowel
#include <stdio.h>
#include <conio.h>
void main()
{
  char xz;
 
  printf("Enter a character\n");
  scanf("%c", &xz);
 
  if ( xz == 'a' ||  xz == 'e' || xz == 'i'  || xz =='o'  || xz == 'u' )
  {
  	printf("%c is a vowel\n", xz);
  	printf("Small case\n");
  }
    
   else if( xz == 'A' || xz == 'E' || xz == 'I' || xz =='O' || xz == 'U' )
   {
   	 printf("%c is a vowel\n", xz); 
   printf("Capital case\n");
   }
  
  else
    printf("%c is not a vowel.\n", xz);
}

Download C check vowel Program

This program check, whether entered character is vowel or not and also checks whether its capital case or small case.

Check entered character is vowel or not using switch

//Check entered character is vowel using switch
#include <stdio.h>
#include <conio.h>
void main()
{
  char xz;
 
  printf("Enter a character\n");
  scanf("%c", &xz);
 
  switch(xz)
  {
    case 'a':
   
    case 'e':
   
    case 'i':
    case 'u':
    case 'o':
    printf("%c is a vowel.\n", xz);
	break;

	case 'A':
	case 'I':
	case 'E': case 'U':
	case 'O':
	printf("%c is a capital case vowel\n", xz);
    break;
    default:
    printf("%c is not  a vowel\n", xz);
  }              
 
 
}

Download c vowel check program

All the thing are same except we are using switch case instead of if-else, you can easily understand. Switch case reduces the complexity of if-else.

See Also

C program string concatenation   |   C program check vowel   |   Java count number of spaces in a string

QUOTES OF THE DAY

Each day provides its own gifts.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER