Adsense 728 * 15

Search

Custom Search

C,C++ Program to Count the Number of Vowels in a String


To solve this problem we simply count the number of vowels in a string. Run the loop till the end of a string and everytime we find any vowel, increment the count by 1.

Program to Check whether Entered Character is Vowel

String Questions

Program to Count the Number of Vowels in a String



#include<stdio.h>
#include<string.h>

void main(){
   
    // Allocated size of string which is 200 character
    char str[200];
    
    int i,count=0;
    
    // Taking input from user
    
    printf("Enter any string");
    gets(str);
    
    // Using strlen we find the length of a string
    
    int len = strlen(str);
    
    
     for(i=0;i<len;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' ){
                count++;
            }
     }
    
    printf("The number of vowels in a string is %d",count);
}

No comments:

Post a Comment