Friday, 13 July 2012

Program to check for Vowel in C


Sample Output - 



Code - 


/* Program to check whether an input alphabet is a vowel or not */

/* Both if statement or switch case can be used */

#include<stdio.h>

#include<conio.h>

int main()
{
    char input_character;

    printf("\n\n\t __ Program to check for vowel or consonant (Using if Statement) __");

    printf("\n\n\n  Enter the Character - ");

    scanf("%c",&input_character);

    /*__ Another way of scanning the character is to use

        input_character = getchar();

    Note - a,e,i,o,u in english character set are known as Vowels */

    if ((input_character == 'o') || (input_character == 'O') || (input_character == 'a') || (input_character == 'A') || (input_character == 'e') || (input_character == 'E') || (input_character == 'i') || (input_character == 'I') || (input_character == 'u') || (input_character == 'U'))
    {
        printf("\n\n\t\t\t __ %c is a Vowel __ ",input_character);
    }
    else
    {
        printf("\n\n\t\t\t __ %c is a Consonant __",input_character);
    }

    getch();

    return 0;

    /* return 0 tells the compiler that the program has
   
                executed successfully without any error */
}




Sample Output - 



Code - 


/* Program to check whether an input alphabet is a vowel or not */

/* Both if statement or switch case can be used */

#include<stdio.h>

#include<conio.h>

int main()
{
    char input_character;

    printf("\n\n\t __ Program to check for vowel or consonant (Using Switch) __");

    printf("\n\n\n  Enter the Character - ");

    scanf("%c",&input_character);

    /*__ Another way of scanning the character is to use

        input_character = getchar();

    Note - a,e,i,o,u in english character set are known as Vowels */

    switch(input_character)
    {
   
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U': printf("\n\n\t\t\t __ %c is a Vowel __ ",input_character);
        break;

    default : printf("\n\n\t\t\t __ %c is a Consonant __",input_character);
   
    }

    getch();

    return 0;

    /* return 0 tells the compiler that the program has
   
                executed successfully without any error */
}



No comments:

Post a Comment