Write a C program to Check Whether a Character is Vowel or Consonant
Program:-
Method : 1
#include <stdio.h>
void vowel_or_consonant(char ch)
{
if ((ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’) || (ch == ‘A’ || ch == ‘E’ || ch == ‘I’ || ch == ‘O’ || ch == ‘U’))
printf(“Vowel\n”);
else
printf(“Consonant\n”);
}
int main()
{
char ch;
printf(“\nInput a character : “);
scanf(” %c”,&ch);
printf(“\n%c is a “,ch);
vowel_or_consonant(ch);
return 0;
}
void vowel_or_consonant(char ch)
{
if ((ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’) || (ch == ‘A’ || ch == ‘E’ || ch == ‘I’ || ch == ‘O’ || ch == ‘U’))
printf(“Vowel\n”);
else
printf(“Consonant\n”);
}
int main()
{
char ch;
printf(“\nInput a character : “);
scanf(” %c”,&ch);
printf(“\n%c is a “,ch);
vowel_or_consonant(ch);
return 0;
}
Output:-
....
Method : 2
#include <stdio.h>
void vowel_or_consonant(char ch)
{
switch(ch)
{
case ‘a’:
case ‘A’:
case ‘e’:
case ‘E’:
case ‘i’:
case ‘I’:
case ‘o’:
case ‘O’:
case ‘u’:
case ‘U’: printf(“Vowel\n”);
break;
default : printf(“Consonant\n”);
}
}
int main()
{
char ch;
printf(“\nInput a character : “);
scanf(” %c”,&ch);
printf(“\n%c is a “,ch);
vowel_or_consonant(ch);
return 0;
}
void vowel_or_consonant(char ch)
{
switch(ch)
{
case ‘a’:
case ‘A’:
case ‘e’:
case ‘E’:
case ‘i’:
case ‘I’:
case ‘o’:
case ‘O’:
case ‘u’:
case ‘U’: printf(“Vowel\n”);
break;
default : printf(“Consonant\n”);
}
}
int main()
{
char ch;
printf(“\nInput a character : “);
scanf(” %c”,&ch);
printf(“\n%c is a “,ch);
vowel_or_consonant(ch);
return 0;
}
Output:-
....
0 comments:
Post a Comment