Sunday, September 2, 2018

Count Vowels

  • Problem Description

    Program to count vowels, consonants,digits and whitespaces
  • CODING ARENA
  • #include <stdio.h>

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

        vowels =  consonants = digits = spaces = 0;
        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;
            }
            else if(line[i]>='0' && line[i]<='9')
            {
                ++digits;
            }
            else if (line[i]==' ')
            {
                ++spaces;
            }
        }

        printf("Vowels:%d",vowels);
        printf("\nConsonants:%d",consonants);
        printf("\nDigits:%d",digits);
        printf("\nWhite spaces:%d", spaces);

        return 0;
    }
  • Test Case 1

    Input (stdin)
    Chennai 378
    
    
    Expected Output
    Vowels:3
    
    Consonants:4
    
    Digits:3
    
    White spaces:1
  • Test Case 2

    Input (stdin)
    Thanjavur is the best city 1000
    
    
    Expected Output
    Vowels:7
    
    Consonants:15
    
    Digits:4
    
    White spaces:5

No comments:

Post a Comment