How To Count Number of Vowels, Consonants, Digits And Spaces In A Sentences Using C++ Program

[812 views]


In this tutorial we will learn how can we count the number of Vowels, Consonants, Digits and Spaces in a sentence using C++. This is a little bit complex program for newbies. But this program is very much useful to learn logics in C++. We will use for loop, if statement and else if statement to complete the program. After running the program it will able to show us how many vowels,consonants, digits, and spaces exist in the given sentence.

How To Count Number of Vowels, Consonants, Digits And Spaces In A Sentences Using C++ Program

C++ Program To Count Number of Vowels, Consonants, Digits And Spaces In A Sentences

#include<stdio.h> #include<iostream.h> #include<conio.h> int main() { char line[150]; int i,v,c,ch,d,s,o; o=v=c=ch=d=s=0; clrscr(); cout<<"Enter a sentence:\n"; gets(line); for(i=0;line[i]!='\0';++i) { if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U') ++v; else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z')) ++c; else if(line[i]>='0'&& line[i]<='9') ++d; else if (line[i]==' ') ++s; } cout<<"Vowels: "<<v; cout<<"\nConsonants: "<<c; cout<<"\nDigits: "<<d; cout<<"\nWhite spaces: "<<s; getch(); }

Output

Enter a sentence: This is 5 C program vowels: 4 Consonants: 9 Digits: 1 White spaces: 4
        

Struggling to Understand Algorithm and Flowchart? Try our Notes



Want to Test Your Knowledge on Algorithm and Flowchart?



Comments



Recommended Deals End in



Search
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Count Number of Consonants In A Sentences Using C++ Program

    Count Number of Digits In A Sentences Using C++ Program

    Count Number of Spaces In A Sentences Using C++ Program