C程序来计算字符串中的元音 [英] c program to count vowels in a string

查看:80
本文介绍了C程序来计算字符串中的元音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c程序来计算字符串中的元音

c program to count vowels in a string

推荐答案

尝试以下操作:

Try this:

char[] vowels = {'a','e','i','o','u'};
string input = txtInput.Text.ToLower();
char[] splittedResult = input.Split('');
int ctr = 0;

foreach(char result in splittedResult)
{
   switch(result)
   case vowels[0]:
   case vowels[1]:
   case vowels[2]:
   case vowels[3]:
   case vowels[4]: ctr++;
                   break;
   default: break;
}



ctr的结果将是元音的数量.

如果这解决了您的问题,请标记为答案并投票5

问候,
爱德华(Eduard)



The result of ctr will be the count of vowels.

Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard


由于这是家庭作业,您不会得到代码!

1)定义并清除计数器.
2)通过字符串中的每个字符开始循环
3)如果字符是元音,则将计数器加1.
3a)可以使用if ... else if ... else
完成 3b)或使用switch
完成此操作 4)循环完成后,计数器将包含元音计数.
Since this is homework you don''t get code!

1) Define and clear a counter.
2) Start a loop through each character in the string
3) If the character is a vowel, increment the counter by one.
3a) This could be done with if...else if...else
3b) Or this could be done with a switch
4) After the loop completes the counter contains the vowel count.


这篇关于C程序来计算字符串中的元音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆