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
Also Prepare Below Important Question
- 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
- Python Program to Delete element at End of Array
- Python Program to Copy one String to Another String
- Python Program to Remove Repeated Character from String
- Print highest frequency Character in String in Python
- Python Program to Convert lowercase vowel to uppercase
- Convert Celsius to Fahrenheit in Python
- Leap Year Program in Python
- Python Program to convert Decimal to Octal number
- Python Program to Convert Decimal Number into Binary
- Find all Pairs Whose Sum is Equal to Given number in Python
- Python Program to Replace First Vowel With ‘-‘ in String
- Python Program to find Prime factors of given integer
- Python Program to Print Prime Number in given range
- Java Program to Perform Left Rotation on Array Elements by Two
- Java Program to Perform Right Rotation on Array Elements by Two
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