Dremendo Tag Line

Input sentence and count total number of vowels present in it in C

String Methods - Question 1

In this question, we will see how to input a sentence and count the total number of vowels present in it in C programming. To know more about string methods click on the string methods lesson.

Q1) Write a program in C to input a sentence and count the total number of vowels present in it.

Program

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

int main()
{
    char s[100];
    char ch;
    int vc=0,i;

    printf("Enter a sentence\n");
    gets(s);

    for(i=0; i<strlen(s); i++)
    {
        ch=tolower(s[i]);
        if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
        {
            vc++;
        }
    }
    printf("Total vowels = %d",vc);
    return 0;
}

Output

Enter a sentence
I am learning C programming
Total vowels = 8
video-poster