Vowel or Consonant
QUESTION:
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
SOLUTION:
#include<stdio.h>
int main()
{
char in;
char arr[11]={'a','e','i','o','u','A','E','I','O','U'};
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;
}
Comments
Post a Comment