Приведенная ниже программа подсчитывает количество гласных букв в строковом слове
#include<stdio.h>
// Global method declaration
int count_vowels(char []);
int check_vowel(char);
int main()
{
printf("nnttStudytonight - Best place to learnnnn");
char aj[100];
int mj;
printf("nnEnter a string : ");
gets(aj); // inputting a string from user
mj = count_vowels(aj); // function call
printf("nnNumber of vowels in string '%s' is: %d", aj, mj);
printf("nnnntttCoding is Fun !nnn");
return 0;
}
/*
Collecting the input string in char array
adi[], all at a time
*/
int count_vowels(char adi[])
{
int count = 0, c= 0, flag = 0;
char d;
do
{
/*
Storing each character of string in
char 'd' one at a time
*/
d = adi[c];
/*
Calling function to check if char is vowel or not
*/
flag = check_vowel(d);
if(flag ==1) // if the char is vowel
{
count++; // increment the count of the vowel
}
c++; // updating the string character to be checked
}while(d != ' '); // terminating condition till it reaches the end of the string
return count;
}
int check_vowel(char ajj)
{
if(ajj >= 'A' && ajj <= 'Z') // if the char is uppercase
ajj = ajj+'a' - 'A'; // converting to lowercase using the ASCII values
// if the char is any of the vowel
if(ajj == 'a' || ajj == 'e' || ajj == 'i' || ajj == 'o' || ajj == 'u')
return 1; // making flag=1
return 0; // if not a vowel, flag remains 0
}