- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print number of words, vowels and frequency of each character
Input a string and find the total number of words, vowels and frequency of a character enter by a user
Input : enter s string : I love my MOM Enter a charcter of which you want to find a frequency: M Total frequency of M : 2 Total number of vowels : 4 Total number of words : 4
Algorithm
START Step 1 Declare array of string, ch, i, freq to 0, vow to 0, word to 0 Step 2 Input a string and a character ch Step 3 Loop for from i to 0 and str[i]!=’\o’ and ++i Step 3.1 IF statement for ch==str[i] Post incrementing freq Step 3.2 End If Step 3.3 IF statement 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' Post incrementing vow Step 3.4 End If Step 3.5 IF statement str[i]=’ ’ Post incrementing word Step 3.6 End If Step 4 End For loop STOP
Example
#include <stdio.h> int main() { char str[1000], ch; int i, freq=0, vow=0, word=0; printf("Enter a string of your choice: "); gets(str); printf("Enter a character of which you want to find the frequency: "); scanf("%c",&ch); for(i = 0; str[i] != '\0'; ++i){ if(ch == str[i]) //to find the frequency of a character { ++freq; } 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') { ++vow; //to find the number of vowels } if (str[i] == ' ') { word++; //to find the number of words } } printf("Frequency of %c = %d", ch, freq); printf("
total number of vowels in a string are %d " ,vow ); printf("
total number of words in a string are %d " ,word+1 ); return 0; }
Output
If we run the above program then it will generate the following output.
Enter a string of your choice: I love PrograMMIng Enter a character of which you want to find the frequency: M Frequency of M = 2 total number of vowels in a string are 6 total number of words in a string are 3
- Related Articles
- Frequency of vowels and consonants in JavaScript
- Frequency of each character in String in Python
- Write a C Program to count the frequency of each character
- How to print number of words in textview in android?
- Number of Valid Words for Each Puzzle in C++
- How to print out the first character of each list in Python?
- Python program to count distinct words and count frequency of them
- How to print the first character of each word in a String in Java?
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string in Python
- Number of vowels within an array in JavaScript
- Java Program to get frequency of words with Lambda Expression
- C# Program to count number of Vowels and Consonants in a string
- Print an N x M matrix such that each row and column has all the vowels in it in C++
- Counting number of vowels in a string with JavaScript
- Sorting string of words based on the number present in each word using JavaScript

Advertisements