In this tutorial we are going to learn writing C program to count the Occurrence of vowels and consonants in a given string. Here we will have two variables that will store the count. Using if else we will check Vowel and Consonants. If vowel occurs then increase vowel counter other wise increase consonant counter.
You can visit below program for the basic understandings
C program to check given character is vowel or consonants.
How our vowel and consonant counter program works?
- Our program will take String as an input.
- We have two integers which will works as the counter of vowel and consonants.
- Logic will be like if vowel comes increase the counter of vowel by 1. And if consonant comes then increase the counter of consonant by 1.
- If character is neither vowel nor consonants then do nothing.
C Program to count vowel and consonant in string
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i,j,len=0, vowel =0, consonant= 0;
printf("C Program to count Vowels and Consonants \n");
printf("Please enter a string : ");
fgets(str, 100, stdin);
len=strlen(str);
for(i=0; i<len; i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
{
vowel++;
} else if((str[i]>=65 && str[i]<=90)|| (str[i]>=97 && str[i]<=122)) {
consonant++;
}
}
printf("Total number of vowels are : %d and Consonants are : %d",vowel,consonant);
return 0;
}
Output 1:
C Program to count Vowels and Consonants
Please enter a string : Quescol
Total number of vowels are : 3 and Consonants are : 4
Output 2:
C Program to count Vowels and Consonants
Please enter a string : Education
Total number of vowels are : 5 and Consonants are : 4
[wpusb]
Also Prepare Below Important Question
- Sum of digits of Given Number in Java
- Hibernate Interview Questions for 2+ years of experience
- 68 Most Important Microservices Interview Questions
- 60 Most Important Git Interview Questions
- 50+ Mostly asked Java Interview Questions for 6 Years Exp.
- 60+ Mostly Asked Java Interview Questions for 4 Years Exp
- 60+ Mostly asked Java Interview Question for 3+ Years
- 60+ Spring Boot interview questions for 4+ years Exp.
- 60+ Mostly Asked Spring Boot Interview Questions for 3+ Yrs
- Scenario Based Java 8 Coding Interview Questions (For Experienced)
- Python Program to add two numbers without addition operator
- Mostly Asked Java Interview Questions For 2 Yrs Experience
- Find All Pairs in Array whose Sum is Equal to given number Using Java
- Java Program to find GCD of two Numbers using Recursion
- Python Program to Separate Characters in a Given String
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array
Interview Questions Categories
C Programming Interview Preparation
Core Java Programming Interview Preparation
- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions