Index-1              Index-2              Home Page

c program to count vowel and consonant

Write a c program to count vowel and consonant from a given string as like "I love Bangladesh"

#include<stdio.h>

main(){

int i , con=0 , vow=0 , space=0 , sentence=0;
char ch[]="i love bangladesh.";

for(i=0;ch[i]!='\0';i++){

if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
vow++;
}
else if(ch[i]==' '){
space++;
}
else if(ch[i]=='.'){
sentence++;
}
else{
con++;
}
}
printf("number of consonant is : %d \n",con);
printf("number of vowel is : %d \n",vow);
}


<< Go to Index Page >>

24 comments:

  1. //Find word sentence vowel consonent operator using file programming
    #include
    #include
    int main()
    {
    FILE *source,*target;
    char source_file[20],target_file[20],ch[250];
    int i,v=0,c=0,a=0,w=1,s=0;
    printf("Enter the file name to retrive string:");
    gets(source_file);
    source=fopen(source_file,"r");
    fgets(ch, 255, (FILE*)source);
    printf("3: %s\n", ch );
    for(i=0;ch[i]!='\0';++i)
    {
    if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' || ch[i]=='o' || ch[i]=='u' ||
    ch[i]=='A' || ch[i]=='E' || ch[i]=='I' || ch[i]=='O' || ch[i]=='U')
    ++v;

    else if((ch[i]>='a' && ch[i]<='z')|| (ch[i]>='A' && ch[i]<='Z'))
    ++c;

    else if(ch[i]=='+' || ch[i]=='-' || ch[i]=='*' || ch[i]=='/' || ch[i]=='%')
    ++a;

    else if(ch[i]==' ')
    ++w;

    else if(ch[i]=='.')
    ++s;

    }
    printf("Vowel: %d\n",v);
    printf("Consonent: %d\n",c);
    printf("Arithmetic Operator: %d\n",a);
    printf("Word: %d\n",w);
    printf("Sentence: %d\n",s);

    printf("Enter a File name to Copy Answer:");
    gets(target_file);
    target=fopen(target_file,"w");
    fprintf(target,"Vowel: %d\n Consonent: %d\nOperator: %d\nWord: %d\nSentence: %d",v,c,a,w,s);
    fclose(target);
    fclose(source);
    return 0;
    }

    ReplyDelete
  2. #include
    #include
    #include
    using namespace std;
    int main ()
    {
    char str[50];
    int v = 0, c = 0;
    cout << "Enter a string : ";
    gets(str);
    for (int i = 0; str[i]!='\0'; ++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')
    ++v;
    else if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
    ++c;
    }
    cout << "Number of vowels : " << v;
    cout << "\nNumber of consonants : " << c;
    return 0;
    }

    ReplyDelete
  3. Md. Aminul Islam Tushar
    ID#201710063

    https://pastebin.com/SEd30ahk

    ReplyDelete
  4. #include

    int main()
    {
    char sentence[100];
    int i, vowels = 0, consonants = 0;

    printf("Enter a sentence \n");
    gets(sentence);
    for (i = 0; sentence[i] != '\0'; i++)
    {
    if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] ==
    'i' || sentence[i] == 'o' || sentence[i] == 'u') ||
    (sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] ==
    'I' || sentence[i] == 'O' || sentence[i] == 'U'))
    {
    vowels = vowels + 1;
    }
    else
    {
    consonants = consonants + 1;
    }

    }

    printf("Number of vowels in %s = %d\n", sentence, vowels);
    printf("Number of consonants in %s = %d\n", sentence, consonants);
    }

    ReplyDelete
  5. Name: Yeasmin Sultana
    ID: 201710251
    solution link: https://ideone.com/MGumUc

    ReplyDelete
  6. ** C++ program to count vowels and consonants in a string :

    #include
    #include
    using namespace std;
    int main()
    {
    char str[200];
    int vowelCounter = 0, consonantCounter = 0;
    cout << "Enter any string: ";
    cin.getline(str, 300);
    for(int i = 0; str[i]!='\0'; 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')
    {
    vowelCounter++;
    }
    else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
    {
    consonantCounter++;
    }
    }
    cout << "Vowels in String: " << vowelCounter << endl;
    cout << "Consonants in String: " << consonantCounter << endl;
    getch();
    }

    Output :
    Enter any string: My Name Is Zoynul Abedin
    Vowels in String: 8
    Consonants in String: 12

    ReplyDelete
  7. Name : Md. Zoynul Abedin
    Roll : 201820591
    Batch : 58-th

    ** C++ program to count vowels and consonants in a string :

    #include
    #include
    using namespace std;
    int main()
    {
    char str[200];
    int vowelCounter = 0, consonantCounter = 0;
    cout << "Enter any string: ";
    cin.getline(str, 300);
    for(int i = 0; str[i]!='\0'; 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')
    {
    vowelCounter++;
    }
    else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
    {
    consonantCounter++;
    }
    }
    cout << "Vowels in String: " << vowelCounter << endl;
    cout << "Consonants in String: " << consonantCounter << endl;
    getch();
    }

    Output :
    Enter any string: My Name Is Zoynul Abedin
    Vowels in String: 8
    Consonants in String: 12

    ReplyDelete
  8. #include

    int main()
    {
    char line[150];
    int i, vowels, consonants;

    vowels = consonants = 0;

    printf("Enter a line of string: ");
    scanf("%[^\n]", 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')
    {
    ++vowels;
    }
    else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
    {
    ++consonants;
    }

    }

    printf("Vowels: %d",vowels);
    printf("\nConsonants: %d",consonants);


    return 0;
    }

    ReplyDelete
  9. https://drive.google.com/open?id=1gly5ifU6_VNB2gOLrgBUpdNur1B9-f0_

    ReplyDelete
  10. https://drive.google.com/open?id=1lpzNvBXzO7IfGoOcsieYgNhZPgcpcWv9

    ReplyDelete
  11. ** C++ program to count vowels and consonants in a string :
    #include
    #include
    using namespace std;
    int main(){
    char str[200];
    int vowelCounter = 0, consonantCounter = 0;
    cout << "Enter any string: ";
    cin.getline(str, 300);
    for(int i = 0; str[i]!='\0'; 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')
    {
    vowelCounter++;
    }
    else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
    {
    consonantCounter++;
    }
    }
    cout << "Vowels in String: " << vowelCounter << endl;
    cout << "Consonants in String: " << consonantCounter << endl;
    getch();
    }

    ReplyDelete
  12. https://drive.google.com/open?id=14uKVVMgHBIPfy97uNV5A-hVOVewnc6pz

    ReplyDelete
  13. https://drive.google.com/open?id=17rwMcz73UrObdIMSoiZcwaDWqEUvuM0-

    ReplyDelete
  14. Name : Firoj Ahmed , Batch : 58th
    ID : 201820222.

    C Program to count vowel and consonant :

    #include
    #include
    #define MAX_SIZE 1000

    int main(){

    char str[MAX_SIZE];
    int i, len, vowel, consonant;

    printf("Enter Any String : ");
    gets(str);

    vowel = 0;
    consonant = 0;
    len = strlen(str);

    for(i=0; i='a' && str[i]<='z') ||(str[i]>='A' && str[i]<='Z'))
    {
    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
    consonant++;
    }

    }
    printf("Total Number Of Vowel is = %d\n", vowel);
    printf("Total Number Of Consonant is = %d\n", consonant);

    return 0;

    }

    ReplyDelete
  15. Name : Firoj Ahmed, Batch : 58th
    ID : 201820222

    C program to count vowel and consonant :

    #include
    #include
    #define MAX_SIZE 1000

    int main(){

    char str[MAX_SIZE];
    int i, len, vowel, consonant;

    printf("Enter Any String : ");
    gets(str);

    vowel = 0;
    consonant = 0;
    len = strlen(str);

    for(i=0; i='a' && str[i]<='z') ||(str[i]>='A' && str[i]<='Z'))
    {
    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
    consonant++;
    }

    }
    printf("Total Number Of Vowel is = %d\n", vowel);
    printf("Total Number Of Consonant is = %d\n", consonant);

    return 0;

    }

    ReplyDelete
  16. 56th Batch
    ID# 201730574

    #include

    void main()
    {
    char sentence[80];
    int i, vowels = 0, consonants = 0, special = 0;
    printf("Enter a sentence \n");
    gets(sentence);
    for (i = 0; sentence[i] != '\0'; i++)
    {
    if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] ==
    'i' || sentence[i] == 'o' || sentence[i] == 'u') ||
    (sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] ==
    'I' || sentence[i] == 'O' || sentence[i] == 'U'))
    {
    vowels = vowels + 1;
    }
    else
    {
    consonants = consonants + 1;
    }
    if (sentence[i] =='t' ||sentence[i] =='\0' || sentence[i] ==' ')
    {
    special = special + 1;
    }
    }
    consonants = consonants - special;
    printf("No. of vowels in %s = %d\n", sentence, vowels);
    printf("No. of consonants in %s = %d\n", sentence, consonants);
    }

    ReplyDelete
  17. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    void vowelCons(string data){
    int i , con=0 , vow=0 , space=0 , sentence=0;

    char ch[] = "I love Bangladesh";

    for(i=0; ch[i] != '\0';i++){
    if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
    vow++;
    }
    else if(ch[i]==' '){
    space++;
    }
    else if(ch[i]=='.'){
    sentence++;
    }
    else{
    con++;
    }
    }
    cout<<"> Number of consonant is : "< Number of vowel is : "<<vow<<".\n";
    }

    };
    main() {
    homeWork hw;
    hw.vowelCons();

    ReplyDelete
  18. #include
    #include
    #include
    #include
    using namespace std;

    class homeWork{
    public:
    wordSentence(string data){
    int word = 1;
    int sentence = 0;
    char ch[] = "I love Bangladesh.";
    for(int i = 0; ch[i] != '\0'; i++){
    if (ch[i] == ' '){
    word++;
    } else if (ch[i] == '.'){
    sentence++;
    }
    }
    cout<<"> Number of word is "< Number of Sentence is "<<sentence<<".\n";
    }

    };
    main(){

    homeWork hw;
    hw. wordSentence ();
    }

    ReplyDelete
  19. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    wrightFile(string data){
    ofstream file_("example.txt", std::ofstream::out | std::ofstream::trunc);
    //file_.open("example.txt");
    if (file_.is_open()){
    file_ < File write successful." << endl;
    } else {
    cout <<"> File not found!" << endl;
    return -1;
    }
    }

    };
    main() {
    homeWork hw;
    hw. wrightFile ();

    }

    ReplyDelete
  20. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    readFile(string data){
    string line_;
    ifstream file_("example.txt");
    //file_.open("example.txt");
    if (file_.is_open()){
    cout <<"> File contents are showing below :"<< endl;
    while(getline(file_,line_)){
    cout<<"| "< File not found!" << endl;
    return -1;
    }
    }
    };
    main() {
    homeWork hw;
    hw.readFile();
    }

    ReplyDelete
  21. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    readWright(){
    string file_data;
    string line_;
    ifstream file_("example.txt");
    //file_.open("example.txt");
    if (file_.is_open()){
    while(getline(file_,line_)){
    file_data += line_+"\n";
    }
    file_.close();
    cout <<"> File data read successful from example.txt."<< endl;
    } else {
    cout <<"> example.txt file not found!" << endl;
    }

    ofstream file("example1.txt", std::ofstream::out | std::ofstream::trunc);
    if (file.is_open()){
    file < File write successful to example1.txt." << endl;
    } else {
    cout <<">example1.txt file not found!" << endl;
    return -1;
    }
    }
    };
    main() {
    homeWork hw;
    hw.readWright();
    }

    ReplyDelete
  22. #include
    #include
    #include
    #include
    using namespace std;
    class homeWork{
    public:
    counter(){
    int vowel, consonant, alphabet, arithmetic, numeric, special, word, sentence;
    vowel = consonant = alphabet = arithmetic = numeric = special = word = sentence = 0;

    char ch[] = "Hello this is nothing. for you 10+2+3=6 and nothing *#.";

    for(int i=1; ch[i] != '\0'; i++){
    if ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')){
    if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
    vowel++;
    } else {
    consonant++;
    }
    alphabet++;
    } else if (ch[i]=='0' || ch[i]=='1' || ch[i]=='2' || ch[i]=='3' || ch[i]=='4' || ch[i]=='5' || ch[i]=='6' || ch[i]=='7' || ch[i]=='8' || ch[i]=='9'){
    numeric++;
    } else if (ch[i] == ' '){
    word++;
    } else if (ch[i] == '.'){
    sentence++;
    } else{
    if(ch[i]=='+' || ch[i]=='-' || ch[i]=='*' || ch[i]=='/' || ch[i]=='%'){
    arithmetic++;
    } else {
    special++;
    }
    }
    }

    cout<<"Total number of vowel is :"< Result stored in example.txt file." << endl;
    } else {
    cout <<"> File not found!" << endl;
    return -1;
    }
    }

    };
    main() {
    homeWork hw;
    hw.counter();

    }

    ReplyDelete
  23. Md.Alamin Hosen
    ID.201910261
    Batch.60th
    //Find word sentence vowel consonent operator using file programming
    #include
    #include
    using namespace std;
    int main()
    {
    char str[200];
    int vowelCounter = 0, consonantCounter = 0;
    cout << "Enter any string: ";
    cin.getline(str, 300);
    for(int i = 0; str[i]!='\0'; i++)
    {
    str[i]=tolower(str[i]);

    if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||
    str[i]=='o' || str[i]=='u' )
    {
    vowelCounter++;
    }
    else if(str[i]>='a'&& str[i]<='z')
    {
    consonantCounter++;
    }
    }
    cout << "Vowels in String: " << vowelCounter << endl;
    cout << "Consonants in String: " << consonantCounter << endl;
    getch();
    }

    ReplyDelete