Saturday 19 March 2016

Vowel or Consonant


Write a program to determine whether the input character is a vowel or consonant.

Input and Output Format: 
Input consists of a single character. Output consists of a string --- “Vowel” / “Consonant” / “Not an alphabet”
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1: 
Enter a character
a
Vowel
Sample Input and Output 2: 
Enter a character
Z
Consonant

Sample Input and Output 3: 
Enter a character
#
Not an alphabet

Code:
  #include<stdio.h>
int main(){
  char in;
  char arr[11]={'a','e','i','o','u','A','E','O','U','I'};
    int i,flag=0,con=0;
  printf("Enter a character\n");
  scanf("%c",&in);
  if(((in>='a') && (in<='z'))||((in>='A')&&(in<='Z')))
  {
    for(i=0;i<10;i++)
    {
      if(in==arr[i]){
        flag++;
        break;
      }
      else
        con++;
    }
  }
  else 
    printf("Not an alphabet\n");
  
  if(con)
    printf("Consonant");
  if(flag)
    printf("Vowel");

  
  
  return 0;
}

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. the above program does not check everycase..
    this program works..
    #include
    #include
    int main()
    {
    char ch;
    char a[20]={'a','e','i','o','u','A','E','I','O','U'};
    int i;
    printf("Enter a character\n");
    scanf("%c",&ch);
    if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='z'))
    {
    for(i=0;i<10;i++)
    {
    if(ch==a[i])
    {
    printf("Vowel");
    exit(0);
    }
    }
    {
    printf("Consonant");
    exit(0);
    }
    }
    else
    {
    printf("Not an alphabet");
    }
    return 0;
    }

    ReplyDelete