String Programming in C


Write a program to count vowel, consonant and word from a given string.

 main()
{
  char line[100];
  int i,con=0,vowel=0,word=0;
  printf("Enter your string :\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')
    ++vowel;
  else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
else if(line[i]==' ')word++;
}
  printf("\nVOWEL : %d",vowel);
  printf("\nCONSONENT : %d",con);
  printf("\nWORD : %d",(word+1));
}

21 comments:

  1. #include
    #include
    #include
    #include
    main()
    {
    char str[100];
    int i,length,consonants=0,vowels=0;
    printf("enter the text");
    gets(str);
    length=strlen(str);
    for(i=0;i<length;i++)
    switch(toupper(str[i]))
    {
    case 'A' :
    case 'E' :
    case 'I' :
    case 'O' :
    case 'U' :vowels++;
    break;
    default : consonants++;
    }
    printf("\n number of vowels=%d",vowels);
    printf("\n number of consonants=%d",consonants);
    getch();
    }

    ReplyDelete
  2. #include
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    printf("Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    printf("\nVOWEL : %d",vowel);
    printf("\nCONSONENT : %d",con);
    printf("\nWORD : %d",(word+1));
    }

    ReplyDelete
  3. #include
    #include
    using namespace std;
    int main()
    {
    string line;
    string::iterator p;
    int i,con=0,vowel=0,word=1;
    printf("Enter your string :\n");
    getline(cin,line,'\n');
    for(p=line.begin();p!=line.end();p++)
    {
    if(*p=='a' || *p=='e' || *p=='i' ||
    *p=='o' || *p=='u' || *p=='A' ||
    *p=='E' || *p=='I' || *p=='O' || *p=='U')
    ++vowel;
    else if((*p>='a' && *p<='z')||(*p>='A' && *p<='Z'))
    ++con;
    else if(*p==' ')word++;
    }
    cout<<"VOWEL : "<<vowel<<"\n";
    cout<<"CONSONENT : "<<con<<"\n";
    cout<<"word : "<<word;
    return 0;
    }

    ReplyDelete
  4. #include
    using namespace std;

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

    vowels = consonants = digits = spaces = 0;

    cout << "Enter a line of string: ";
    cin.getline(line, 150);
    for(int 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;
    }
    else if(line[i]>='0' && line[i]<='9')
    {
    ++digits;
    }
    else if (line[i]==' ')
    {
    ++spaces;
    }
    }

    cout << "Vowels: " << vowels << endl;
    cout << "Consonants: " << consonants << endl;
    cout << "Digits: " << digits << endl;
    cout << "White spaces: " << spaces << endl;

    return 0;
    }

    ReplyDelete
  5. #include
    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<< "Enter your string :\n";
    cin.getline(line, 100);
    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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')

    word++;

    }
    cout<< "VOWEL :"<< vowel<<endl;
    cout<< "CONSONENT : "<< con<<endl;
    cout<< "WORD : "<< word+1 <<endl;
    }

    ReplyDelete
  6. Md.Nazrul Islam, ID:201630769January 25, 2017 at 9:58 PM

    #include
    #include
    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<<"Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    cout<<"\nVOWEL :"<<vowel;
    cout<<"\nCONSONENT :"<<con;
    cout<<"\nWORD : "<<word+1;
    }

    ReplyDelete
  7. Md.Nazrul Islam, ID:201630769January 25, 2017 at 10:04 PM

    #include
    #include
    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<<"Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    cout<<"\nVOWEL :"<<vowel;
    cout<<"\nCONSONENT :"<<con;
    cout<<"\nWORD : "<<word+1;
    }

    ReplyDelete
  8. Md.Nazrul Islam, ID:201630769January 26, 2017 at 5:28 AM

    #include
    #include
    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<<"Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    cout<<"\nVOWEL :"<<vowel;
    cout<<"\nCONSONENT :"<<con;
    cout<<"\nWORD : "<<word+1;
    }

    ReplyDelete
  9. #include

    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<<"Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    cout<<"\nVOWEL :"<<vowel;
    cout<<"\nCONSONENT :"<<con;
    cout<<"\nWORD : "<<word+1;
    }

    ReplyDelete
  10. #include

    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<<"Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    cout<<"\nVOWEL :"<<vowel;
    cout<<"\nCONSONENT :"<<con;
    cout<<"\nWORD : "<<word+1;
    }

    ReplyDelete
  11. #include

    using namespace std;
    main()
    {
    char line[100];
    int i,con=0,vowel=0,word=0;
    cout<<"Enter your string :\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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')word++;
    }
    cout<<"\nVOWEL :"<<vowel;
    cout<<"\nCONSONENT :"<<con;
    cout<<"\nWORD : "<<word+1;
    }

    ReplyDelete
  12. ID : 201620195
    https://www.dropbox.com/s/kcttb7zvc2fqif1/04.cpp?dl=0

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. ID:204520552
    1)https://drive.google.com/open?id=0B5pG0kIjzgEKVlNUdUNSMjcyLWc
    2)https://drive.google.com/open?id=0B5pG0kIjzgEKUGc3ZUNyeUY3Mzg

    ReplyDelete
  15. Summer 2017
    ID#201610042

    https://drive.google.com/file/d/0B99eePh0LV8gTjNVd3lqWjRvU1k/view?usp=drivesdk

    ReplyDelete
  16. MD USUF MIA
    ID 201610456
    link:
    https://drive.google.com/open?id=0B_PIGnOMR0K2a2ZaSzhOcHNXTGc

    ReplyDelete
  17. MD USUF MIA
    ID 201610456
    https://drive.google.com/open?id=0B_PIGnOMR0K2a2ZaSzhOcHNXTGc

    ReplyDelete
  18. https://drive.google.com/open?id=0B5eevQy6QwSOS3BmU0YtWkJoR0E

    ReplyDelete
  19. https://drive.google.com/open?id=0B5eevQy6QwSOc3lFSmduYnFoUjQ

    ReplyDelete
  20. #include
    #include
    using namespace std;

    class check
    {
    public:
    char line[100];
    int i,con=0,vowel=0,word=1;
    check()
    {
    cout<<"Enter your string:";
    gets(line);

    }
    void cal()
    {
    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')
    ++vowel;
    else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))
    ++con;
    else if(line[i]==' ')
    word++;
    }
    cout<<"vowel:"<<vowel<<endl;
    cout<<"Consonent:"<<con<<endl;
    cout<<"Word:"<<word;
    }
    } ;
    int main()
    {
    check obj;
    obj.cal();
    return 0;
    }

    ReplyDelete