🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. Introduction
A fundamental exercise in C programming for beginners involves understanding conditional statements through the classification of alphabets. One such common problem is to determine whether a given character is a vowel or a consonant. In this guide, we will learn how to write a C program to check whether a given character is Vowel or Consonant.
2. Program Overview
1. Prompt the user to input a character.
2. Convert the character to lowercase to ensure the check is case insensitive.
3. Use a switch-case statement to determine if the character is a vowel (i.e., 'a', 'e', 'i', 'o', or 'u').
4. If it's a vowel, print the result; if it's not a vowel and is an alphabet, it's a consonant. If it's neither a vowel nor a consonant (not an alphabet), inform the user.
3. Code Program
#include <stdio.h>
int main() {
char c;
int isLowercaseVowel, isUppercaseVowel;
// Asking user to input a character
printf("Enter a character: ");
scanf("%c", &c);
// Check if it's one of the lowercase vowels
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// Check if it's one of the uppercase vowels
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// Determine the type of the character
if (isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) // Check if it's an alphabet character
printf("%c is a consonant.", c);
else
printf("%c is not an alphabet character.", c);
return 0;
}
Output:
Enter a character: e e is a vowel. Enter a character: D D is a consonant. Enter a character: 1 1 is not an alphabet character.
4. Step By Step Explanation
1. The user is prompted to input a character.
2. Two integer variables, isLowercaseVowel and isUppercaseVowel, are used to store the result of checking whether the character is a lowercase or uppercase vowel, respectively.
3. If the character is either a lowercase or uppercase vowel, it is identified as a vowel.
4. If it's not a vowel but lies within the alphabetic range (either lowercase or uppercase), it's identified as a consonant.
5. Otherwise, the character is neither a vowel nor a consonant, so it's identified as not an alphabet character.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment