7 May 2010

C Program to check for Vowel or Consonant Alphabets

Here you can find the c code for checking whether the entered character is vowel or a consonant. In this program, I have also taken into account few failure cases when the user enters any special characters or any number instead of the expected alphabets. This program is also programmed to allow the user to enter alphabets in any case either Upper or Lower.


One thing which has to be kept in mind is that if the user enters more than one character, only the first character will be considered.

The C code can be found below:

/*
C program to check for vowel or consonant alphabets
By: Amit Biswal
URL: http://amitbiswal.blogspot.com
*/
#include <stdio.h>
#include <conio.h>
int main()
{
    char c;
    printf("Enter a character to check for vowels\n");
    scanf("%c",&c);
    if((c>='a' && c<='z')|(c>='A' && c<='Z'))
    {          
        if(c=='a' | c=='e' | c=='i' | c=='o' | c=='u' | c=='A' | c=='E' | c=='I' | c=='O' | c=='U' )
        printf("\nVowel");
        else
        printf("\nConsonant");
    }
    else
    {
        printf("Enter Only Alphabets");
    }

    getch();
    return 0;
}



Related Post :


0 comments:

Post a Comment

If you liked this blog then Join me at:
Facebook
Twitter
RSS