C program to check(determine) whether character is vowel or consonant

In this post, we will write a C program to check whether the input entered by the user is Vowel or consonant

character(alphabet) entered by the user is Vowel if the character belongs to a small or capital letter, 'A', 'E', 'I', 'O', 'U' or 'a', 'e', 'i', 'o', 'u'. All other alphabets are consonant

c program to check whether a character is vowel or consonant

program to determine whether the character is vowel or consonant

#include<stdio.h>
int main()
{
	char c;
	printf("\n Enter the character:");
	scanf("%c",&c);
	if(c=='a'|| c=='e' || c=='i'|| c=='o'|| c=='u'|| c=='A'|| c=='E'
	|| c=='I'|| c=='O'||c=='U')
	{
		printf("\n %c is a vowel",c);
	}
	else
	{
		printf("%c is a consonant",c);
	}
    return 0;
}

output

Enter the character:U
U is a vowel

In this program, the user must take input alphabet only. if the user enters a non-alphabet character, the output will be a character as a consonant. to fix the above problem, see the below program

program to check vowel or consonant in c using if-else

#include<stdio.h>
int main()
{
    char c;
    printf("\n Enter the character");
    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("\n %c is a vowel",c);
        }
        else
        {
            printf("\n %c is a consonant",c);
        }
    }
    else {
        printf("\n %c is a neither Vowel not constant",c);
    }
}

output 1

Enter the character:a
a is a vowel

output 2

Enter the character:Enter the character:d
d is a consonant

Explanation of vowel or consonant program

  • In this program, you will take input from the user and stored it in variable c.
  • if the value entered by the user in  c matches with 'A', 'E', 'I', 'O', 'U' or 'a', 'e', 'i', 'o', 'u', then output will vowel.
  • if the value of c is not matched with 'A', 'E', 'I', 'O', 'U' or 'a', 'e', 'i', 'o', 'u', then output will consonant.