用于计算C中发生的元音的程序(Program to count vowels occurrent in C)

优质
小牛编辑
120浏览
2023-12-01

实现 (Implementation)

现在,我们将看到该计划的实际执行情况 -

#include <stdio.h>
int main() {
   char s[] = "TajMahal";     // String Given
   int i = 0;
   int vowels = 0;            // Vowels counter
   int consonants = 0;        // Consonants counter
   while(s[i++] != '\0') {
      if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' )
         vowels++;
      else
         consonants++;
   }
   printf("'%s' contains %d vowels and %d consonants.", s, vowels, consonants);
   return 0;
}

输出 (Output)

该计划的输出应为 -

'TajMahal' contains 3 vowels and 5 consonants.