Slip 27 - A) Write a program to count the occurrences of vowel from a input string.

Solution:


#include <stdio.h>
int main()
{
    char line[150];
    int i, vowels;
    vowels = 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;
        }
            }
    printf("Vowels: %d",vowels);
       return 0;
}

Post a Comment

0 Comments