Write a c program to check whether a character is vowel or consonant. In this program, we take an input character from a user and our code will check whether an input character is vowel or consonant.
Before start writing code, let's first understand what is vowel and consonant?
What is vowel and consonant?
In english, Alphabet a, e, i, o, u is called vowel and rest of the alphabets is called consonant.
In this example, we take an input alphabet from a user and then compare with a, e, i, o, u (upper and lower case both). If input character is matches then it's a vowel otherwise it's a consonant.
Output :
Enter an alphabet : a
a is a vowel
C Program to print 1 to 100 numbers without using loop
C program to reverse a number
In this example, we use switch statement to check whether an input alphabet is vowel or consonant. The logic is same. In this case, we solve this problem in another way using switch statement.
Programming question on Arrays
Programming question on Linked List
Sorting algorithm and their time complexity
Stack implementation
Programming questions using Recursion
C, C++ interview questions
Programming Books
Before start writing code, let's first understand what is vowel and consonant?
What is vowel and consonant?
In english, Alphabet a, e, i, o, u is called vowel and rest of the alphabets is called consonant.
How to Check whether a Character is Vowel or Consonant
1. Take an input character from a user.
2. Compare input character with a, e, i, o, u, A, E, I, O, U. If it matches with any of them then it's a vowel otherwise it's a consonant.
C program to concatenate two strings
C program to concatenate two strings
C Program to Check Whether a Character is Vowel or Consonant
In this example, we take an input alphabet from a user and then compare with a, e, i, o, u (upper and lower case both). If input character is matches then it's a vowel otherwise it's a consonant.
#include <stdio.h> int main(void) { //Declar char char alpha; // Take a input character from a user printf(" Enter an alphabet\n"); scanf("%c", &alpha); //Compare if ( alpha == 'a' || alpha == 'A' || alpha == 'e' || alpha == 'E' || alpha == 'i' || alpha == 'I' || alpha =='o' || alpha=='O' || alpha == 'u' || alpha == 'U') { printf("%c is a vowel", alpha); } else { printf("%c is a consonant", alpha); } return 0; }
Output :
Enter an alphabet : a
a is a vowel
C Program to print 1 to 100 numbers without using loop
C program to reverse a number
C Program to Check Whether a Character is Vowel or Consonant using Switch Statement
In this example, we use switch statement to check whether an input alphabet is vowel or consonant. The logic is same. In this case, we solve this problem in another way using switch statement.
#include <stdio.h> int main(void) { char alpha; // Take an input character from a user. printf(" Enter an alphabet \n"); scanf("%c", &alpha); switch(alpha) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': printf("%c is a vowel", alpha); break; default: printf("%c is not a vowel", alpha); } return 0; }
Programming question on Arrays
Programming question on Linked List
Sorting algorithm and their time complexity
Stack implementation
Programming questions using Recursion
C, C++ interview questions
Programming Books
Thank you for your help.
ReplyDeletehave tried the same program on visual studio ultimate 2012 but have found two errors.
ReplyDelete1. on the opening brace after the "if (condition)" it says Error: expected an expression.
2. on the last brace that closes the whole code the error is 'expected a ')'
This comment has been removed by a blog administrator.
ReplyDelete