反转字符串中的元音字符_C程序消除字符串中的所有元音

反转字符串中的元音字符

Given a string and we have to eliminate/ remove all vowels from the string using C program.

给定一个字符串,我们必须使用C程序从字符串中消除/删除所有元音。

To eliminate/remove the vowels

消除/删除元音

  • We will traverse (reach) each elements by using a loop

    我们将使用循环遍历(到达)每个元素

  • And, check the each element, if any element found as vowel, we will remove that shifting all other elements to the left

    并且,检查每个元素,如果发现任何元素为元音,我们将删除将所有其他元素向左移动的操作

  • Finally, we will print the string - that will be a string without the vowels

    最后,我们将打印字符串-这将是没有元音的字符串

Example:

例:

    Input:
    String is: "Hello World"
    
    Output:
    String after removing vowels: "Hll Wrld"


程序从C的字符串中消除所有元音 (Program to eliminate all vowels from the string in C)

/* C program to eliminate all the vowels
* from the entered string
*/
#include <stdio.h>
#include <string.h>

int main()
{
    char string[50] = { 0 };
    int length = 0, i = 0, j = 0, k = 0, count = 0;

    printf("\nEnter the string : ");
    gets(string);

    length = strlen(string);
    count = length;
    for (j = 0; j < length;) {
        switch (string[j]) {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
            for (k = j; k < count; k++) {
                string[k] = string[k + 1];
                //printf("\nstring : %s",string);
            }
            count--;
            break;
        default:
            j++;
        }
    }
    string[count] = '\0';
    printf("Final string is : %s", string);
    return 0;
}

Output

输出量

Enter the string : Hello World
Final string is : Hll Wrld


翻译自: https://www.includehelp.com/c-programs/eliminate-all-vowels-from-a-string.aspx

反转字符串中的元音字符

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值