C语言例程:元音字母的统计

从终端上输入若干个字符,对其中的元音字母进行统计。

#include <stdio.h>
#include <stdlib.h>
static void test3(void)
{
    int ct_a = 0,ct_e = 0,ct_i = 0,ct_o = 0,ct_u = 0;
    int ch;
    ch = getchar();
    while(ch != '#')
    {
        switch(ch)
        {
            case 'a':
            case 'A':
                ct_a ++;
                break;
            case 'e':
            case 'E':
                ct_e ++;
                break;
            case 'i':
            case 'I':
                ct_i ++;
                break;
            case 'o':
            case 'O':
                ct_o ++;
                break;
            case 'u':
            case 'U':
                ct_u ++;
                break;
               default:
               	ptus("请再输入一次");
               		break;        
        }
    }
    printf("A/a is %d E/e is %d I/I is %d O/o is %d U/u is %d\n",ct_a,ct_e,ct_i,ct_o,ct_u);
}

int main()
{
    test3();
    exit(0);
}

猜你喜欢

转载自blog.csdn.net/weixin_45075787/article/details/114223008
今日推荐