Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Program to count number of vowels and consonants in a string

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 817
    Comment on it

    Counting number of vowels,consonants and digits in a string:

    In this program we are counting how many vowels ,consonants and digits are in the string which will be entered by the user. After user inputs a string , string will be iterated from 0th index to last index means until it not terminate with null.

    • The variable vowel will count the number of vowels and variable con will count the number of consonants in the string.
    • Digit variable will count the number of digits in a string.

    #include<string.h>
    void main()
    {
     char str[10];
     int b,digit,vowel,e,i,l,con;
     b=digit=vowel=e=0;

    printf("\n\t Enter any string :"); scanf("%s",str);

    for(i=0;str[i]!='\0';i++) { if((str[i]>=65&&str[i]<=90||str[i]>=97&&str[i]<=122)) b++; if(str[i]>=48&&str[i]<=57) digit++; // digit variable will be incremented if digits found 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++; // vowel variable will be incremented if vowels found if (str[i]==' ') e++; } con=b-vowel; // it will count the number of consonants in the string

    printf("\n\t No of vowels=%d \n",vowel); printf("\n\t No of consonants=%d \n ",con); printf("\n\t No of digits=%d \n",digit);

    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: