C Program to Check if a Character is Vowel or Constant
In this article, we will learn How to determine or check if a character is vowel or constant or number or a special character using the C programming language.
To solve this problem, we need some fundamental concepts of C programming (the main function, if-else, variables, I/O, etc). Also, we have to know the iteration technique of alphabet and numbers in C.
Algorithm – Check if a Character is Vowel or Constant
- We will write all of our business logic inside our main function.
- Declare a character variable called ch inside the main function.
- After that, scan/ask the user for taking a character input and put it into the ch variable.
- Now, first, check if the input character is alphabet or not. If it is an alphabet then write another check if it is a vowel, display the character and also display it is a vowel. If it is not a vowel then display the character and display it is constant.
- At the first check, if it is not an alphabet, then check if it is a number or not. If it is a number then display the number.
- If the number checking logic fails to determine the number then simply print out “You entered a special character.”
C Program to Check if a Character is Vowel or Constant
#include <stdio.h>
int main() {
char ch;
printf("Enter a Character: ");
scanf("%c", &ch);
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
printf("The charater '%c' is an alphabet.", ch);
if(ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' ||
ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' ||
ch == 'U' || ch == 'u'
) {
printf(" And it is a Vowel!\n");
} else {
printf(" And it is a Constant!\n");
}
} else if (ch >= '0' && ch <= '9') {
printf("The character '%c' is a number.\n", ch);
} else {
printf("You entered a special character.\n");
}
return 0;
}
- Copy and paste the code in a file and save with .c file extension. Then run it with your favorite IDE to see the output;
Sample Input | Sample Output |
---|---|
Enter a Character: C | The charater ‘C’ is an alphabet. And it is a Vowel! |
Enter a Character: 8 | The charater ‘8’ is a number. |
Enter a Character: $ | You entered a special character. |
General Learning Output (GLO)
- Uses of the declaration of C main function.
- Declaring character variable in C programming.
- Scanf function uses and declaration syntax along with character variable input.
- Basic conditional statement and its syntax used in C programming with complex logic making with AND (&&), OR (||) operator.
- Lines are manually wrappable, Which means we can break any line when a single expression is so large. So for good readability, we can break the line just like the above code.
- Displaying info to the console using printf function.
- C program to print Integer & Decimal number given by user
- C Program to perform all arithmetic calculation
- C program to ask two numbers and find their sum
- C program to check a number is even, odd or zero
- C program to swap between two numbers
- C program to sum of natural numbers up to N
- C program to calculate the factorial of a number
- C program to make a multiplication table
- C program to calculate GCD of two numbers
- C program to calculate LCM of two numbers
- C program to count number of digits in a number
- C program to reverse a integer number
- C program to find the power of a number
- C program to check whether a number is palindrome or not
- C program to count and print prime numbers up to the N
- C program to check armstrong numbers
- C program to check armstrong numbers between two integers
- C program to find factors of a number
- C program to fined the size of all data types
- C program to print largest number among three numbers
- C program to check a number is positive or negetive
- C program to calculate the factorial of a number
- C program to form any kind of pyramid and stracture
- C program to find all the prime numbers between two numbers
- C program to check whether a number is prime or not
- C program to make a simple calculator
- C program to calculate the perimeter of a rectangle
- C program to calculate the area of a rectangle
- C program to calculate the diameter and area of a circle
- C program to convert kilometer to meter and centimeter
- C program to convert temperature celsius to fahrenheit
- C program to convert temperature fahrenheit to celsius
- C program to ask for days and convert into years, week and days
- C program to calculate the square root of a given number
- C program to find third angle of a triangle where two angles are given
- C program to calculate the area of a triangle
- C program to calculate area of an equilateral triangle
- C program to calculate average and percentage of result
- C program to calculate simple loan interest
- C program to compound loan interest
- C program to display fibonacci series of a number
- C program to swap two numbers without using third variable
- C program to print Hello World without using semicolon
- C program to insert assembly code and run it
- C program to printf Hello world without main() function
- C program to to calculate the multiplication of two matrix
- C program to convert decimal numbers into binary
- C program to form a triangle made with alphabet
- C program to form a triangle made with numbers
- C program to form a fibonacci triangle
- C program to convert a number into charecters
Happy Coding 🙂